Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 20th, 2004, 08:29 PM
duniyadnd duniyadnd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 30 duniyadnd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 44 m 4 sec
Reputation Power: 0
Regular Expression

I created a simple function to check for regular expressions, but it returns with no matches and I can't figure out what is wrong with it. Any help would be great. Thanks

---------------------------------------------------
Code:
import urllib
import re

def Content(content):
  required = 'a'
  p = re.compile(required, re.IGNORECASE)
  #print content
  print "\n\nMatch is: \n"
  gr = p.match(content)
  print gr
  print "\n\nGroup is: \n"
  print gr.groups()

s = 'japana'
Content(s)


I keep getting "None" matches.

Reply With Quote
  #2  
Old April 21st, 2004, 02:38 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,585 DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 58 m 23 sec
Reputation Power: 1372
The problem is that regexObj.match() only matches at the start of the string. What you want to use is regexObj.search(), which will find the pattern anywhere in the string.

Also, if you use the matchObj.groups() method then you need to define at least one group in you pattern, e.g. '(a)', otherwise it will always return an empty tuple. If you just want to return the matched string then use matchObj.group().

Dave - The Developers' Coach

Reply With Quote
  #3  
Old April 21st, 2004, 10:08 AM
duniyadnd duniyadnd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 30 duniyadnd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 44 m 4 sec
Reputation Power: 0
Aaaaah, i should have mentioned that. I already tried group, and I had already put the paranthesis around 'a' as '(a)' but I still get "none" as matches

Reply With Quote
  #4  
Old April 22nd, 2004, 11:14 AM
duniyadnd duniyadnd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 30 duniyadnd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 44 m 4 sec
Reputation Power: 0
Figured out the problem when someone told me, that it was looking only for those letters, and not within the words.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Regular Expression

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap