简体   繁体   中英

Find certain data with regular expression

I have a file in the following format:

someinformation="someNumbers"-result

My code is:

re.findall('someinformation="(.*?)"-result', str(data))

Given the example:

test1="3"-result

I want to get 3 , but my code doesn't find anything.

re.findall('test1=(.*?)-result', str(data))

works, but returns "3" and not 3 . What I find strange is that the following:

  re.findall('test1="3"-result', str(data))

doesn't find anything either.

You have a syntax error in following code :

re.findall('test1="3"-result'), str(data))

Just remove the extra parenthesis and see the result,also note that if you defined your string like following you won't need to use str function at all :

>>> data='test1="3"-result'
>>> re.findall('test1="3"-result', data)
['test1="3"-result']

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