This question was asked here, but I do not want a python specific solution. It should work in JavaScript, and any other mainstream language. It must be a regular expression.
Suppose that the delimiter was "!
"
The table below shows the desired behavior for a few sample inputs
+------------------------+--------+
| INPUT | OUTPUT |
+------------------------+--------+
| "aaaa!bbbb" | "aaaa" |
| "aaaa" | "aaaa" |
| "aaaa!bbbb!ccccc!dddd" | "aaaa" |
| "aaaa!" | "aaaa" |
| "!aaaaa" | "" |
+------------------------+--------+
I tried the following to no avail:
"^[^!]*$(!)
"
You don't need (!)
at the end. Just use ^([^!]*)
.