I'm trying to create a regex to match a string, which has a *
placeholder. The problem for me is, that this placeholder could optionally have some characters in front:
I came up with /(.*)(\w)\*(.*)/
:
This is ju* an example
This is * an example
T* is just an example
* is just an example
This is just an ex*
This is just an *
I need to get three parts of each string:
- The first part of the string before the placeholder (with optional prepended string),
- the prepended placeholder string itself and
- the rest of the string.
So the result should be:
This is|ju|an example
This is|<null>|an example
<null>|T|is just an example
<null>|<null>|is just an example
This is just an|ex|<null>
This is just an|<null>|<null>