String manipulation advice needed.
Josiah Carlson
jcarlson at uci.edu
Wed Oct 13 14:53:40 EDT 2004
More information about the Python-list mailing list
Wed Oct 13 14:53:40 EDT 2004
- Previous message (by thread): String manipulation advice needed.
- Next message (by thread): String manipulation advice needed.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> 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
- Previous message (by thread): String manipulation advice needed.
- Next message (by thread): String manipulation advice needed.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list