English 中文(简体)
编号:Trouble with Regex in-030
原标题:Number Trouble with Regex in Python
  • 时间:2012-01-12 15:09:45
  •  标签:
  • python
  • regex

I m试图过滤从C.csv档案中检索的一个日期,但我似乎没有尝试合并。 日期为“2011-10-01 19:25:01”或“年月:分钟:无”。

I want just the year, month and date but I get can t seem to get ride of the time from the string:

date = bug[2] # Column in which the date is located  
date = date.replace( " ,  ) #getting rid of the quotations  
mdate = date.replace( : ,  )  
re.split( $[d]+ ,mdate) # trying to get rid of the trailing set of number (from the time)

提前获得咨询意见。

最佳回答
问题回答

我认为,你重新混淆了一条线和美元线的开端。 Try ^[d-]+

如果格式总是<代码>,YYYYY-MM-DD HH:mm:ss”,则尝试:

date = date[1:11]

In a prompt:

>>> date =  "2012-01-12 15:13:20" 
>>> date[1:11]
 2012-01-12 
>>> 

无需reg

>>> date =  "2011-10-01 19:25:01" 
>>> date.strip( " ).split()[0]
 2011-10-01 

贵组织守则的一个问题是,在你最后的定期表述中,$与扼杀的结束相吻合,这样经常表达永远不会与任何内容相匹配。 你可以更简单地通过空间分化来做到这一点,只取得初步结果。 删除引号后,线

date.split()

<[>2011-10-01”、“19:25:01”>>>,因此该清单的第一个要素是您的需要。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签