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


Groups > comp.lang.javascript > #21586

Re: regular expression

Message-ID <1692823.iOv17HgRNK@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-10-10 21:33 +0200
Subject Re: regular expression
Newsgroups comp.lang.javascript
References <l36qvt$6rq$1@dont-email.me>

Show all headers | View raw


Tony Johansson wrote:

> I want to filter this expression
> http://localhost:49507/slutProjekt/img/TwinBagel.jpg

That is _not_ an expression.  It is a URI.  It would be an expression if you 
enclosed it in string delimiters.

> by using regular expression so that I only want the string that starts
> after the last / and end before the dot.
> In this example I want just TwinBagel.
> I have this expression elmnt.src.replace(/^.*[\\\/]/, '');
> but this will also return the string after the dot which I don't want.

  var s = elmnt.src.replace(/^.*\/([^.]+).*/, '$1');

Better:

  var m = (elmnt.src.match(/([^.\/]+)(?:\..*?)?$/) || [])[1];

See also:

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String>
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp>.

AISB, use <http://tools.ietf.org/html/rfc3986#appendix-B> as template for 
parsing URIs.

-- 
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

regular expression "Tony Johansson" <johansson.andersson@telia.com> - 2013-10-10 20:17 +0200
  Re: regular expression "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-10-10 20:29 +0200
  Re: regular expression Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-10 21:33 +0200
    Re: regular expression Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-10-10 21:31 +0100
      Re: regular expression Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-10 22:57 +0200
        Re: regular expression Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-10-10 23:56 +0100
          Re: regular expression Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-11 01:06 +0200
            Re: regular expression Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-10-11 01:21 +0100
  Re: regular expression RobG <rgqld@iinet.net.au> - 2013-10-10 18:48 -0700
    Re: regular expression Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-10-11 11:42 +0200
  Re: regular expression dhtml <dhtmlkitchen@gmail.com> - 2013-10-16 10:19 -0700

csiph-web