By the string below, I want to extract words between delimters []
such as 'Service', 'service', '9991 ',' 1.22 '
:
str =' mysrv event generated event name [service current], category [ Service]
Div class = "post-text" itemprop = "Text">
First of all, avoid using str
as a variable name. str
already has a meaning in Python and you can confuse people by defining it to do something else.
It is said that you can use the following regular expression:
<> & gt; & Gt; & Gt; Import re & gt; & Gt; & Gt; Print Refund (R '[[[^]] *) \]', S) ['Service On', 'Service', '9991 ',' 1.22 ']
It works as follows:
\ [Matching anything except a catalyting group [^]] one match, * match with zero or more] Close the capturing group is an optional regular expression :r '[[ It works like this
]
/ P>
Comments
Post a Comment