Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #20581

Re: Regexp confusion

Message-ID <9161127.hJ6kbhveRM@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-07-07 22:18 +0200
Subject Re: Regexp confusion
Newsgroups comp.lang.javascript
References <sh5vv3omcuc2$.1ls4uvq7bzu5d$.dlg@40tude.net> <c1df98f5-f298-4131-b7a9-fd6c054b92bf@googlegroups.com>

Show all headers | View raw


dann90038@gmail.com wrote:

> To JJ

<http://www.netmeister.org/news/learn2quote.html>
<http://jibbering.com/faq/#posting>
<http://PointedEars.de/faq#posting>

> it works for me in js if I use
> \.feed(burner|sportal)\.com\/|feed.*\.gif($|\?)*

Which is nonsense.  Neither can the end of input/line be repeated, nor is 
the “?” allowed to be repeated (unescaped) in a “http(s):”-URI-Reference.
 
> and I get matches on all 3 with the string
> http://feeds.feedburner.com/any
> http://feed.thesite.com/any/blah.gif
> http://feedsite.com/any/blah.gif?var=blah

And you also get a match for

  http://feedsite.com/any/blah.gif??????????var=blah

which certainly is _not_ a valid “http(s):”-URI-Reference.
 
> it also works with
> \.feed(burner|sportal)\.com\/|feed.*\.gif($|\?)
> if my string alone is
> http://feed.thesite.com/any/blah.gif
> 
> so, I'd think there's something after the ".gif" which isn't $ end of
> input or "?" character

RFC 3986, Appendix B, contains a *proper* regular expression for matching 
URIs that can be adapted to result in

  /\.feed(burner|sportal)\.com\/|feed[^?]*\.gif(\?[^#]*)?(#.*)?$/

or (non-greedy matching, probably not worth the incompatiblity here)

  /\.feed(burner|sportal)\.com\/|feed[^?]*\.gif(\?.*?)?(#.+)?$/

It is possible that this is still not what the OP needs as then there can 
only be query-part and fragment-part if a resource name was specified (“/a|
b(c?)/” ≡ “/(?:a)|(?:b(c?))/”).  A more viable solution might be

  /(\.feed(burner|sportal)\.com\/|feed[^?]*\.gif)(\?[^#]*)?(#.*)?$/
   ^                                            ^
or

  /(\.feed(burner|sportal)\.com\/|feed[^?]*\.gif)(\?.*?)?(#.+)?$/
   ^                                            ^
Note the extra parentheses that group the outer alternation.  Also, where 
non-greedy matching is supported, potentially more efficient non-capturing 
parentheses are supported, for example:

  /(?:\.feed(?:burner|sportal)\.com\/|feed[^?]*\.gif)(\?.*?)?(#.+)?$/

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Regexp confusion JJ <duh@nah.meh> - 2013-07-08 00:26 +0700
  Re: Regexp confusion dann90038@gmail.com - 2013-07-07 12:21 -0700
    Re: Regexp confusion Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-07-07 22:18 +0200
  Re: Regexp confusion Denis McMahon <denismfmcmahon@gmail.com> - 2013-07-07 20:28 +0000
  Re: Regexp confusion JJ <duh@nah.meh> - 2013-07-08 08:24 +0700
    Re: Regexp confusion Andreas Bergmaier <andber93@web.de> - 2013-07-08 17:51 +0200
      Re: Regexp confusion JJ <duh@nah.meh> - 2013-07-09 03:58 +0700

csiph-web