You are not logged in.
when grouping tokens together like this:
/\/web(\/.*)?/g
does that make the trailing '/' between the brackets () optional?
so it would match:
/web
/website
/web/1
or is it mandatory and match only:
/web/
/web/whatever
Figured out the above, but still can't get grep to work.
I've been trying to figure it out and test this expression with grep but it's not working. I created a simple test file:
web
/web
/web/
/web/1
web/2
/web/sdfk3
Doesn't seem to matter whether I escape or not, but it seems to trip over the grouping ().
So why doesn't either of the below work?
grep '\/web(\/.*)?' test
grep '/web(/.*)?' test
grep '/\/web(\/.*)?/g' test
Thanks!
Last edited by mouseman (2016-01-02 09:33:13)
Offline
I hope I'm not horribly wrong here but grep is in basic regex mode by default (BRE) and you need extended (ERE)
Basic vs Extended Regular Expressions
In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use
the backslashed versions \?, \+, \{, \|, \(, and \).
Try adding the -E flag to grep
Last edited by oliver (2015-12-22 14:19:06)
Offline
Ah, learned something about grep.
This works:
egrep '/web(/.*)?' test
Thanks!
Offline