string - Python : extract all items that match a pattern -
is there strait forward way in python extract items match pattern, items between 2 characters (for example $$)
i have tried using
split("$""$")
on string looks
string = "$this$ $is$ $some$ $data$"
with aim of getting looks this
string = [ $this$, $is$, $some$, $data$ ]
however doesn't work, there strait forward way extract matches pattern in python?
how following code?
>>> import re >>> s = "$this$ $is$ $some$ $data$" >>> re.findall(r'\$[^$]*\$', s) ['$this$', '$is$', '$some$', '$data$']
Comments
Post a Comment