String manipulation advice needed.
Josiah Carlson
jcarlson at uci.edu
Wed Oct 13 14:53:40 EDT 2004
> What is the easiest way of getting this information out of a string:
>
> foo = "My number 70 is what I want to parse" => 70
> foo = "My info {info} between the curly brackets is what I want to parse" => {info}
> foo = "My info between [hello world] is what I want to parse" => [hello world]
>
> At this moment my way to go is splitting the strings in substring, and do different checks on these substrings like:
> - try: int(substring)
> - substring.find('{') or substring.find('[')
>
> Works but.. my guess is that it can be way more smarter, I must miss a strong library that can help me in simplifying the job.
Regular Expressions are your freind. Take a peek at the re module.
- Josiah
More information about the Python-list
mailing list