Regex expression in Python to match text after words and between angle brackets -
given string: "group <stuffhere> user <iwantthis> ip <notimportant> address <ialsowantthis> assigned",
how extract things in brackets after 'user' , address. take above string , return
(iwantthis, ialsowantthis)
try this, it'll match text between <>:
s = "group <stuffhere> user <iwantthis> ip <notimportant> address <ialsowantthis> assigned" ans = re.findall(r'<(.+?)>', s) now it's easy extract parts we're interested in:
ans[1] => 'iwantthis' ans[3] => 'ialsowantthis'
Comments
Post a Comment