0

How to match asterisk in string, If I remove * from the string in following code It works fine. It gives me list of 7.9. Any solution to make it work with that '*' after multiplier in string.

import re

line = r"multiplier* : 7.9";

reg = re.compile(r'\b(?:multiplier\*?)\b\s*:?\s*(\d+\.?\d*)')
searchObj = re.findall( reg, line )

if searchObj:
   print(searchObj)
else:
   print("Nothing found!!")
P.Natu
  • 131
  • 1
  • 3
  • 12
  • Replace it with `(?!\w)` if you really want to fail the match is there is a word char immediately to the right of the current position. If that does not work for you please edit the question to add the specific cases that fail. – Wiktor Stribiżew Apr 28 '20 at 07:47
  • The word boundary `\b` does not match after matching the `*` – The fourth bird Apr 28 '20 at 07:49

0 Answers0