Re: help with another regex

2018-07-17 Thread Lauren C.
I think reading the official tutorial from begin is not that comfortable to a newbie. I bought a book "Learning Perl, 6th Edition" for studying step by step. thanks. On 2018/7/18 星期三 AM 9:08, Uri Guttman wrote: also i always recommend reading the entire perl FAQ as there are many regex tips a

Re: help with another regex

2018-07-17 Thread Uri Guttman
On 07/17/2018 08:57 PM, Lauren C. wrote: I did read them, but got no deep impression unless I met the issue. :) not sure what kind of deep impression you need! :) a key thing with docs is rereading them. read them once quickly all the way through to get a sense of the whole picture. read aga

Re: help with another regex

2018-07-17 Thread Lauren C.
I did read them, but got no deep impression unless I met the issue. :) Uri Guttman 写道: On 07/17/2018 08:46 PM, Lauren C. wrote: Thanks Gil. I think i know the difference of "\w+" and "\w*" now. lauren, did you read the perlretut document? if not, you should. it covers quantifiers early on a

Re: help with another regex

2018-07-17 Thread Uri Guttman
On 07/17/2018 08:46 PM, Lauren C. wrote: Thanks Gil. I think i know the difference of "\w+" and "\w*" now. lauren, did you read the perlretut document? if not, you should. it covers quantifiers early on as they are one of the fundamental features of regexes. a key thing to learn is the {m,n}

Re: help with another regex

2018-07-17 Thread Lauren C.
yeah you explain that well. thanks. Andy Bach 写道: > But it doesn't work for this case: $ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}' > it expects 1 returned. Well, assuming you mean it shouldn't match as $x starts with a slash and the RE doesn't - you're on the right path.  The reas

Re: help with another regex

2018-07-17 Thread Lauren C.
Thanks Gil. I think i know the difference of "\w+" and "\w*" now. Gil Magno 写道: 2018-07-17 19:56:59 +0800 Lauren C.: Hello, I want to match: /path/ /path/123 /path/abc but /path/?xxx should not be matched. This works: $ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}' 1 this works

Re: help with another regex

2018-07-17 Thread Andy Bach
> But it doesn't work for this case: $ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}' > it expects 1 returned. Well, assuming you mean it shouldn't match as $x starts with a slash and the RE doesn't - you're on the right path. The reason is, the match goes anywhere, it is "unanchored" so Pe

Re: help with another regex

2018-07-17 Thread Gil Magno
2018-07-17 19:56:59 +0800 Lauren C.: > Hello, > > I want to match: > > /path/ > /path/123 > /path/abc > > but /path/?xxx should not be matched. > > This works: > > $ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}' > 1 > > > this works too: > > $ perl -le '$x="/path/?abc"; print 1 if

Re: help with another regex

2018-07-17 Thread Илья Рассадин
Hi! I think, m{path/(\w+)?/?$} regex can solve your problem. In general, to parse URL, you can use official regex from rfc3986 (see Appendix B for rfc3986) regex is ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? $2 is protocol $4 is host $5 is path $7 is query $9 is fragment. Ano

help with another regex

2018-07-17 Thread Lauren C.
Hello, I want to match: /path/ /path/123 /path/abc but /path/?xxx should not be matched. This works: $ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}' 1 this works too: $ perl -le '$x="/path/?abc"; print 1 if $x=~m{path/\w+}' But it doesn't work for this case: $ perl -le '$x="/pa