The problem:
I need to extract strings that are between $ characters from a block of text, but i'm a total n00b when it comes to regular expressions.
For instance from this text:
Li Europan lingues $es membres$ del sam familie. Lor $separat existentie es un$ myth.
i would like to get an array consisting of:
{'es membres', 'separat existentie es un'}
A little snippet in Python would be great.
Import the re module, and use findall():
>>> import re
>>> p = re.compile('\$(.*?)\$')
>>> s = "apple $banana$ coconut $delicious ethereal$ funkytown"
>>> p.findall(s)
['banana', 'delicious ethereal']
The pattern p represents a dollar sign (\$), then a non-greedy match group ((...?)) which matches characters (.) of which there must be zero or more (*), followed by another dollar sign (\$).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With