| | |
Regular Exp
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jun 2005
Posts: 23
Reputation:
Solved Threads: 1
Sorry, I know that this is probably the wrong section to post this question in, but I'm sort of confused as to which one would have been appropriate. Anyways, I've been using regular expressions to find specific information such as e-mail addresses and whatnot inside textfiles, but I can't get my head over this one problem.
The problem my expression faces, is getting it to stop looking at a string. I was wondering if there's anyway I could expand the NOT parameters to include entire strings, rather then just one character.
For example, given the string:
Only pick up strings without Capital letters!
My regular expression would get:
Only pick up strings without Capital letters!
Any help would be great
The problem my expression faces, is getting it to stop looking at a string. I was wondering if there's anyway I could expand the NOT parameters to include entire strings, rather then just one character.
For example, given the string:
Only pick up strings without Capital letters!
My regular expression would get:
Only pick up strings without Capital letters!
Any help would be great
I wrote this little function in Python. It scans a string and returns True the moment it finds a capital letter, otherwise False. Hope this helps ...
python Syntax (Toggle Plain Text)
# tested with Python24 def hasCap(s): """returns True if the string s contains a capital letter""" for num in range(65, 91): # A to Z capLetter = chr(num) if capLetter in s: return True return False str1 = 'Only pick up strings without Capital letters!' str2 = 'only pick up strings without capital letters!' # test the function hasCap() if hasCap(str1): print "str1 has a capital letter" else: print "str1 has no capital letter" if hasCap(str2): print "str2 has a capital letter" else: print "str2 has no capital letter"
Last edited by vegaseat; Oct 25th, 2009 at 2:25 pm. Reason: update code tags
May 'the Google' be with you!
I stopped at this regex for Python site:
http://www.amk.ca/python/howto/regex/
to refresh my brain on regex. I am really rusty!
http://www.amk.ca/python/howto/regex/
to refresh my brain on regex. I am really rusty!
May 'the Google' be with you!
•
•
Join Date: Jun 2005
Posts: 23
Reputation:
Solved Threads: 1
Thanks for your help. :mrgreen:
It took me quite a while, but I found out how to do it. Just in case anyone else has similar problems, what I did was I made an or statement that said the first letter had to be a space, followed by a capital, or a capital at the start of a string.
It took me quite a while, but I found out how to do it. Just in case anyone else has similar problems, what I did was I made an or statement that said the first letter had to be a space, followed by a capital, or a capital at the start of a string.
Last edited by Rete; Jun 29th, 2005 at 8:53 pm. Reason: typo
![]() |
Similar Threads
- Regex for password (Shell Scripting)
- mod_rewrite: help with regular expressions (Linux Servers and Apache)
- matching regular expressions (Java)
- Do u use your root account on a regular basis? (*nix Software)
Other Threads in the Python Forum
- Previous Thread: ftplib and the retrbinary() command
- Next Thread: Function that creates random changes in a string??
| Thread Tools | Search this Thread |
accessdenied advanced application argv beginner change color command convert csv cursor def dictionary digital dynamic dynamically edit editing enter event examples excel file float format frange function google gui homework i/o import input jaunty java keyboard lapse line linux list lists loop microphone mouse movingimageswithpygame newb number numbers numeric obexftp output parameters parsing path port prime programming projects py2exe pygame pygtk pyopengl python random recursion remote return reverse scrolledtext session simple skinning smtp sprite stderr string strings subprocess syntax table tennis terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode unit urllib urllib2 variable voip web-scrape windows wxpython






