As per title I need to parse string of the form string_1\string_2
as in a string followed by a backslash then by another string with the following requirements:
- if string_1 and string_2 are present, break them into two tokens:
string_1
and\string_2
- if only string_1 is present, return it
- if
\string_2
is present but nothing behind the backslash, don't match anything.
So far I've come up with this :
^([\w\s]*)((?!\\\).*)
but the last character in string_1 keeps 'leaking' through and going to string_2 right before the backslash.
Is there a way to fix that? Or any other alternative regex? The following regex does helps with the leaking but it break the third requirement.
^([\w\s]*).((?!\\\).*)
In order to make sure this question is not too localized, note that this could help parse a subset of latex when you have a string coming before say \section{section title comes here {*}}
.