I have a regex expression found here. Try out the strings below, the problem I'm facing is that there's an extra whitespace located at the beginning of each captured group after the 1st one. I need the whitespace to be matched but I don't need them to be captured.
Regex expression:
^(\/[a-zA-Z0-9]+)?(\s~[a-zA-Z]+)?([\w\s'()-]+)?((?:\s~[a-zA-Z]+){0,2})?$
Viewing it at the link above makes it much simpler to comprehend.
These are some strings you can paste into the test string area one by one:
/test ~example matches ~extra ~space
this too has an extra ~space ~matched
/like wise for this
/and ~this
Take a look at the match groups area and notice that after the 1st group, the 1 preceding whitespace between groups are captured.
What I want to do is this:
For the 1st and 2nd capture group, I want them to detect a succeeding space and absorb it but not capture it, so that the 3rd capture group won't detect and capture the extra space. For the 4th capture group, I want it to detect a preceding space and absorb it but not capture it.
What I mean by absorb is that the space gets "removed" in a sense that the 3rd capture group won't realize it's there.
How can I do this?
Thanks.