简体   繁体   中英

Parsing string in Python

I have python string s that contains data structured in this way:

INFO: some text...
INFO: some text...
INFO: some text...
INFO: some text...
223A

I need to extract just number 223 from whole string and put it in another integer variable. How would I do that?

You can use that to eliminate non-numeric characters from a string

import re
re.sub("[^0-9]", "", string_to_be_parsed)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM