python - Need help in this Regular Expression -
the regular expression using:
%s??[a-z](:\d+|)(^\[)?
the string is:
"%sprix %s[4] online %s[3]:6 pshopping %s:9 in %s"
i trying find %s
string except %s[4]
, %s[3]
.
my output using above regular expression not giving expected results.
expected output is:
%s, %s:9, %s
my output is:
%s, %s[ , %s[, %s:9, %s
you may use
%s(?!\[)(?::\d+)?
see regex demo.
details:
%s
- percentage sign ,s
(?!\[)
- not followed[
(?::\d+)?
- optional sequence of:
, 1 or more digits
the above regex fail match in cases when %s
followed [
, e.g. in %s[text
. if want fail match when %s
followed [
+number+]
, use %s(?!\[\d+\])(?::\d+)?
.
Comments
Post a Comment