I've tried googling this but all I can find is how to match until a known character occurs. In my case I don't know the character beforehand.
I know I can match the last character of a string with (.?)$
, and I know that I can match until a character X occurs with (?:(?!X).)*
, but how do I combine the two to match until the first occurence and not the matched occurence?
Examples:
character → char
test → t
no match → no match
This is a test → This is a t
I came. I saw. I conquered. → I came.
In pseudocode what I want is basically str.substring(0,str.indexOf(str.lastChar))
.