-2

I'm trying to get python regex to match the end of a string (primarily because I want to remove a common section off the end of the string. I have the following code which I think is how the docs describe to do it, but it's not performing as I'm expecting:

input_value = "Non-numeric qty or weight, from 00|XFX|201912192009"
pattern = ", from .*$"
match = re.match(pattern , input_value)
print(match)

The result is None, however I'm expecting to have matched something. I've also tested these values with an online regex tool: https://regex101.com/ using the python flavour, and it works as expected.

What am I doing wrong?

Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476
Andy
  • 2,826
  • 4
  • 31
  • 53

1 Answers1

0
match = re.match(".*, from.*$", input_value)

you should use .* infront else it will try to fin exact match

PDHide
  • 15,234
  • 2
  • 19
  • 35