Regular Expression Problem...

Doran_Dermot at emc.com Doran_Dermot at emc.com
Wed Dec 1 07:35:40 EST 2004


You could try the following:
regex = re.compile("[\$]\w+", re.IGNORECASE)

I've only done a bit of testing.  Maybe somebody has a better solution.

Cheers!!

Dermot. 

-----Original Message-----
From: python-list-bounces+doran_dermot=emc.com at python.org
[mailto:python-list-bounces+doran_dermot=emc.com at python.org] On Behalf Of
andrea.gavana at agip.it
Sent: 01 December 2004 12:23
To: python-list at python.org
Subject: Regular Expression Problem...

Hello NG,

     I am quite new with Python... I'm writing an application that does
also some regexp things on strings, but I'm having problem about
identifying/extracting a substring from another string. What I have to do
is to extract all the strings that begins with a "$" character, but
excluding characters like "." (point) and "'" (single quote) and "\" "/"
(slashes). For example I have:

1) This Is An $EXAMPLE String
2) This Is An $EXAMPLE.String
3) 'This Is An $EXAMPLE'
4) This Is An \$EXAMPLE\String;

I would like to extract only the "keyword" $EXAMPLE and what I'm using at
the moment is:

#CODE BEGIN
import re

mystring = "This Is An \$EXAMPLE\String;"
regex = re.compile("[\$]+\S*",re.IGNORECASE)
keys = regex.findall(mystring)

#CODE END

Obviously this code returns things like $EXAMPLE', $EXAMPLE/, $EXAMPLE. and
so on...
Does anyone have a suggestion?

Thank you a lot.

Andrea.

----------------------------------------------------------------------------
--------------------------------------------------------------

Message for the recipient only, if received in error, please notify the
sender and read http://www.eni.it/disclaimer/

-- 
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list