简体   繁体   中英

Regex python Match after and before a specific string

Lets say we have this string:"Code: 1 ,Some text some other text {fdf: more text, attr = important "

I want to catch the pattern using Regex that can findall attr and extract important and 1 and put them in dict.

I tried this one :

(?<=testcaseid_)[^_]+_[^_]+

but still capture all the previous

I'm not sure if I understand well, but if you want to get everything starts from "1" to something after attr= you can also use regex like this:

r"1.*?attr=\w+"

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