Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

Fetching specific data within the quotes using regex in python

I am trying to fetch the plugin version from the config XML file(fread) using regex. Using the following regex. But I am getting the entire line instead, I am just interested in the version i.e "4.3.0". Any help on how that can be achieved?

(Pdb) key
'plugin="git'
(Pdb) re.findall(key+".*",fread)
['plugin="[email protected]">\n    <configVersion>2</configVersion>\n    <userRemoteConfigs>\n      <hudson.plugins.git.UserRemoteConfig>\n    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This may not be the most optimal regex check, but it does work: Regexr Tester The link will explain how the capture works. From that just strip the string of the @ symbol.

this would also allow for finding multiple sets if they are defined if you want a more precise check you can search for git@ blah blah blah and return all of those then just strip the front part essentially


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...