python regular expressions
Hi All, I'm starting to learn python. I was looking for a python equivalent to a perl regular expression such as $_ = "FreeBSD"; /(.*)BSD/; where $1 would get what ever is between '(...)', 'Free' in this case. Is there a way i can make use of the () regex operator in python? I can't seem to find an equivalent in python's regex module (re). Thanks, --brad
okay i figured it out, For those intersted ... text = "FreeBSD" reg_obj = re.compile('(.*)BSD') search_res = reg_obj.findall(text) print search_res[0] --brad On Fri, Aug 23, 2002 at 09:37:02PM -0400, Brad Noyes wrote:
Hi All,
I'm starting to learn python. I was looking for a python equivalent to a perl regular expression such as
$_ = "FreeBSD"; /(.*)BSD/;
where $1 would get what ever is between '(...)', 'Free' in this case.
Is there a way i can make use of the () regex operator in python? I can't seem to find an equivalent in python's regex module (re).
Thanks, --brad
_______________________________________________ Wlug mailing list Wlug@mail.wlug.org http://mail.wlug.org/mailman/listinfo/wlug
I didn't see this when you sent it the first time... There is a another way to do this. text = "FreeBSD" results = re.search(r'(.*)BSD', text) print results.groups(1) the compile() command is typically used for long regex expressions so the programmer doesn't need to write again and again. :-) A good Python book is the New Riders "Python Essential Reference". Its a small book with just the language references, plenty of examples, and its written by the creator of Python. Phil On Wed, 28 Aug 2002, Brad Noyes wrote:
okay i figured it out, For those intersted ...
text = "FreeBSD" reg_obj = re.compile('(.*)BSD') search_res = reg_obj.findall(text) print search_res[0]
--brad
On Fri, Aug 23, 2002 at 09:37:02PM -0400, Brad Noyes wrote:
Hi All,
I'm starting to learn python. I was looking for a python equivalent to a perl regular expression such as
$_ = "FreeBSD"; /(.*)BSD/;
where $1 would get what ever is between '(...)', 'Free' in this case.
Is there a way i can make use of the () regex operator in python? I can't seem to find an equivalent in python's regex module (re).
Thanks, --brad
_______________________________________________ Wlug mailing list Wlug@mail.wlug.org http://mail.wlug.org/mailman/listinfo/wlug
_______________________________________________ Wlug mailing list Wlug@mail.wlug.org http://mail.wlug.org/mailman/listinfo/wlug
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Phil Deneault "We work in the dark, We do what we can, deneault@wpi.edu We give what we have. Our doubt is our passion, WPI NetOps and our passion is our task. The rest is the InfoSec maddness of art." - Henry James -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
On Wed, Aug 28, 2002 at 12:06:08PM -0400, Phillip G Deneault wrote:
I didn't see this when you sent it the first time...
There is a another way to do this.
text = "FreeBSD" results = re.search(r'(.*)BSD', text) print results.groups(1) Yes, i saw this somewhere as well.
Question: what is the r'...' used for, and what does it mean?
the compile() command is typically used for long regex expressions so the programmer doesn't need to write again and again. :-)
in the script i was writing i ended up using the compile option, but left that out in my mail for simplicity.
A good Python book is the New Riders "Python Essential Reference". Its a small book with just the language references, plenty of examples, and its written by the creator of Python.
Thanks for your input! --brad
On Wed, 28 Aug 2002, Brad Noyes wrote:
okay i figured it out, For those intersted ...
text = "FreeBSD" reg_obj = re.compile('(.*)BSD') search_res = reg_obj.findall(text) print search_res[0]
--brad
On Fri, Aug 23, 2002 at 09:37:02PM -0400, Brad Noyes wrote:
Hi All,
I'm starting to learn python. I was looking for a python equivalent to a perl regular expression such as
$_ = "FreeBSD"; /(.*)BSD/;
where $1 would get what ever is between '(...)', 'Free' in this case.
Is there a way i can make use of the () regex operator in python? I can't seem to find an equivalent in python's regex module (re).
Thanks, --brad
_______________________________________________ Wlug mailing list Wlug@mail.wlug.org http://mail.wlug.org/mailman/listinfo/wlug
_______________________________________________ Wlug mailing list Wlug@mail.wlug.org http://mail.wlug.org/mailman/listinfo/wlug
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Phil Deneault "We work in the dark, We do what we can, deneault@wpi.edu We give what we have. Our doubt is our passion, WPI NetOps and our passion is our task. The rest is the InfoSec maddness of art." - Henry James -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
_______________________________________________ Wlug mailing list Wlug@mail.wlug.org http://mail.wlug.org/mailman/listinfo/wlug
On Wed, Aug 28, 2002 at 03:23:49PM -0400, Brad Noyes wrote:
Question: what is the r'...' used for, and what does it mean?
"raw" quotes, roughly analagous to perl's qw/.../ -- Frank Sweetser fs at wpi.edu, fs at suave.net | $ x 18 Full-time WPI Network Engineer, Part time Linux/Perl guy | "Endorsing products is the American way of expressing individuality." -Calvin
On Wed, 28 Aug 2002, Brad Noyes wrote:
On Wed, Aug 28, 2002 at 12:06:08PM -0400, Phillip G Deneault wrote:
I didn't see this when you sent it the first time...
There is a another way to do this.
text = "FreeBSD" results = re.search(r'(.*)BSD', text) print results.groups(1) Yes, i saw this somewhere as well.
Question: what is the r'...' used for, and what does it mean?
It denotes a 'raw' string input and add special characters accessed by the \ key. For instance r'\<html\>(.*)\<\/html\>' searches between the <html></html> tags. There are other characters too, for instance, \d only matches number digits and is the equivalent to r'[0-9]'. If you use this method, its easiest to just leave the r'' notation in. That way, everything is consistent and you can use a whole list of shortcuts. Phil -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Phil Deneault "We work in the dark, We do what we can, deneault@wpi.edu We give what we have. Our doubt is our passion, WPI NetOps and our passion is our task. The rest is the InfoSec maddness of art." - Henry James -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
participants (3)
-
Brad Noyes
-
Frank Sweetser
-
Phillip G Deneault