Regular Expression in Python

N

newPeter

Hi,

I am trying to figureout some data from python,

pat = re.compile(r'^(.{3})(\d{1})\w|\s')

pat.search(' 183 14 1 1282 0 2004-11-08/13:26:14.21').groups()

it searches and matches the record rightly: output willbe:
(' 183 ', '1')

but if i am trying to search for one digit e.g,

pat = re.compile(r'^(.{13})(\d{1})\w|\s')
pat.search(' 183 14 1 1282 0 2004-11-08/13:26:14.21').groups()

output is: (Nothing,Nothing)

is there any restrction from Python or my code needs some correction?
Thanks,
SF.
 
A

Ann

newPeter said:
Hi,

I am trying to figureout some data from python,

pat = re.compile(r'^(.{3})(\d{1})\w|\s')

pat.search(' 183 14 1 1282 0 2004-11-08/13:26:14.21').groups()

it searches and matches the record rightly: output willbe:
(' 183 ', '1')

but if i am trying to search for one digit e.g,

pat = re.compile(r'^(.{13})(\d{1})\w|\s')
pat.search(' 183 14 1 1282 0 2004-11-08/13:26:14.21').groups()

output is: (Nothing,Nothing)

is there any restrction from Python or my code needs some correction?
Thanks,
SF.

Do you need to escape your curly brackets?
I don't understand the dot.
 
C

Chris Smith

newPeter said:
I am trying to figureout some data from python,

Yes. I'm rather confused why you've posted in a Java newsgroup.
Perhaps you should try comp.lang.python instead.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top