PHP Regex: group must end with character but do not capture this character -
example regex:
/^([\w]+:)?other:(.*)$/
example string:
test:other:words...
the first group match "test:", want capture "test". @ first thought:
/^([\w]+)?:?other:(.*)$/
but realised can't have single : in beginning. how can capture group if exists must end : : must not captured group?
example input , output:
randomstring:constantstring:somethingelse
should give 'randomstring' first group.
and
constantstring:somethingelse
should give first group empty
Comments
Post a Comment