Reputation: 1150
I'm trying to put together a Regex matching all but last occurrence of a specific character (say exclamation mark !), into a group, and then everything else into another group.
Examples:
a!1
a!!1
a!1!a!!a
It is safe to assume that the special character cannot be at the start, or the end of the string.
Ideally I want all this to be achieved in
Thanks, Stevo
Upvotes: 0
Views: 906
Reputation: 495
(.*)\!(.*)
Matched test inputs/outputs here http://www.myregextester.com/index.php
Upvotes: 2
Reputation: 1848
this should catch anything before the last ! in a capturing group, and everything after in the other capturing group
(.*)!([^!]*)
Upvotes: 0