Reputation: 99
I'm struggling to create a Regex that will capture if the string:
/
?
/?
But doesn't match something like /foo
or /foo/bar
.
So far I'm here:
(|/|/?\?.+)
but it's still matching /foo
and /foo/bar
Upvotes: 0
Views: 502
Reputation: 785286
You may use this regex for your job:
^/?(\?.+)?$
RegEx Details:
^
: Start/?
: Match optional /
at the start(\?.+)?
: Match string starting with ? till end with 1+ characters after
?`$
: EndUpvotes: 2