Current location: Hot Scripts Forums » Programming Languages » Other Languages » regex match problem


regex match problem

Reply
  #1 (permalink)  
Old 03-19-07, 01:10 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
regex match problem

i'm trying to get a certain string from a code snippet. i'm using the re (regex) package, but there seems to be a small problem:
when i use the method findall() it works fine, it displays exactly what i want, but when i use match, it returns None.

this is the code i'm using:
Python Code:
  1. import re
  2. code = "private void handleUpdateConstructionRequestEvent( UpdateConstructionRequestEvent event)"
  3.  
  4. reg_method = re.compile('([A-Z][a-zA-Z0-9\._]+)\s?\(', re.S)
  5. print "findall:"
  6. print reg_method.findall(code)
  7. print "match:"
  8. print reg_method.match(code)
When i run it, i get this output:
Code:
findall:
['UpdateConstructionRequestEvent']
match:
None
does anybody have an idea why?

thx in advance,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #2 (permalink)  
Old 03-19-07, 01:26 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
never mind :s

i found it. after carefully reading the docs again, i saw why it wasn't working:
Quote:
match() : Determine if the RE matches at the beginning of the string.
search() : Scan through a string, looking for any location where this RE matches.
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
regex problem (another one) UnrealEd PHP 4 10-24-06 05:10 PM
Can regex solve this problem? sujata_ghosh Perl 14 08-08-06 12:47 AM
About preg_match_all klaniak PHP 4 05-28-06 04:59 PM
PHP Regular Expressions Jaffizzle PHP 3 11-05-05 07:02 PM
Help with part of a PHP code cynebald PHP 3 07-29-05 05:07 AM


All times are GMT -5. The time now is 03:41 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.