I would like to extract value from a key=value pair (String) in Python, using regular expression (re.compile and match). I am new to Python. Any help appreciated...
I want the value of LICENSE i.e abcd-efgh-1234-34ki
I tried the below, but it is not exactly working
license_regex = re.compile('.LICENSE=.?.*')
match = license_regex.match(line)
=> prints the whole line.
then I tried with (.?)!.' => doesn't print anything
then the captured group will have the desired portion.
^.*? lazily matches upto a empty string followed by
(.*) matches the rest, and put in captured group 1
In : s = '[INFO] LICENSE=abcd-efgh-1234-34ki' In : re.search(r'^.*?\bLICENSE=(.*)', s).group(1) Out: 'abcd-efgh-1234-34ki'