Help in Regular Expression

This is the place for queries that don't fit in any of the other categories.

Help in Regular Expression

Postby deathmetal » Mon Apr 08, 2013 3:11 pm

Hi Seniors/Forum Members,

I am new to python programming. I have recently started my work on Python. To begin with, I am working on Regular expression. I am using aptana 3 studio, windows 7.

Code: Select all
s='greddy'
t='^[a-z]$'

g=re.search(t,s)

I get a negative result. I am unable to understand it. :oops:
However, if I use t as '[^a-z]$' or t as '^[a-z$]', I get result as expected. :geek:

Can someone please explain, where am I going wrong? Any shall be of greatly appreciated.
deathmetal
 
Posts: 6
Joined: Mon Apr 08, 2013 3:05 pm

Re: Help in Regular Expression

Postby setrofim » Mon Apr 08, 2013 3:43 pm

You are trying to match a single character in the range [a-z]. You want to mach one or more characters, the regex should be
Code: Select all
t='^[a-z]+$'
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Help in Regular Expression

Postby deathmetal » Mon Apr 08, 2013 4:36 pm

Thank you very much. :)
so in this way, it will searching from the end, with occurrence 0 or more times, which starts with Single letter between a-z.
I hope I am correct. :roll:
deathmetal
 
Posts: 6
Joined: Mon Apr 08, 2013 3:05 pm

Re: Help in Regular Expression

Postby setrofim » Mon Apr 08, 2013 4:43 pm

Not quite. It searches for one or more occurances (+) of a lower case character ([a-z]) between the start (^) and end ($) of the input.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Help in Regular Expression

Postby deathmetal » Mon Apr 08, 2013 5:06 pm

Oh. That way.
Thank you for your time and reply. :)
deathmetal
 
Posts: 6
Joined: Mon Apr 08, 2013 3:05 pm


Return to General Coding Help

Who is online

Users browsing this forum: cmajor28 and 4 guests