[Python-Dev] help required (original) (raw)
MRAB python at mrabarnett.plus.com
Fri Sep 25 21:36:44 CEST 2009
- Previous message: [Python-Dev] help required
- Next message: [Python-Dev] Python 2.7 Mac universal builds seem broken on trunk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
waqas ahmad wrote:
Hi,
I dont know it is the right place to post this question. I need help to change one search code line . can you help me please. here is my search method code: search=re.compile("^#acl InternationalGroup.*\n", re.M).search(pagetext) if search: ret=search.group()
here i am searching for "#acl InternationalGroup" in the pageText and when it true is then give me search group. I want to change this for following requirement: I want to search for "#acl InternationalGroup" and "CatInternational" in the pageText. when "#acl InternationalGroup" is not there but "CatInternational" is there. then return me search group. I shall be thankful to you for any help. I'm not clear whether you want the search to succeed if pageText contains either, or if pageText contains "CatInternational" but not "#acl InternationalGroup".
Whichever you want, you could use 2 simple separate regular expressions or 1 more complicated regular expression.
Search for either:
search = re.compile("^#acl InternationalGroup.*\n", re.M).search(pagetext) if not search: search = re.compile("^CatInternational.*\n", re.M).search(pagetext) if search: ret = search.group()
Search for one but not the other:
search = re.compile("^CatInternational.*\n", re.M).search(pagetext) if search: search_2 = re.compile("^#acl InternationalGroup.*\n", re.M).search(pagetext) if not search_2: ret = search.group()
- Previous message: [Python-Dev] help required
- Next message: [Python-Dev] Python 2.7 Mac universal builds seem broken on trunk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]