I’m parsing an external feed which contains location and date inside post title which I want to get rid of, so:
This happened on Date in Location
I need to find on (space on space) and remove everything till the end of the line, same for in(space in space).
I googled a bit, but regex is really unfathomable for me so I’d appreciate any help.
Thanks!
Well, a literal “
on” does match exactly. Then tell the regex engine to match everything after: “.*“. (Note, that the.doesn’t match newlines, so it works as needed.)In the case of “
in” you need an alternative, which is marked by parentheses()and the vertical bar|: “(on|in)“. You could also make that a bit tighter with character classes[]: “[oi]n“.With that we arrive at this regex: