Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #21591
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| Content-Type | text/plain; charset="ISO-8859-1" |
| Message-ID | <2009598.r5QypLNUnr@PointedEars.de> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Organization | PointedEars Software (PES) |
| Date | Fri, 11 Oct 2013 01:06:27 +0200 |
| User-Agent | KNode/4.10.5 |
| Content-Transfer-Encoding | 7Bit |
| X-Face | %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== |
| Subject | Re: regular expression |
| Newsgroups | comp.lang.javascript |
| References | <l36qvt$6rq$1@dont-email.me> <1692823.iOv17HgRNK@PointedEars.de> <0.59968aeff2274c0aa6ab.20131010213157BST.8738o827gi.fsf@bsb.me.uk> <4522206.f2d4svmm8S@PointedEars.de> <0.db90040c6be3639c247a.20131010235624BST.87r4bszqef.fsf@bsb.me.uk> |
| MIME-Version | 1.0 |
| Lines | 47 |
| NNTP-Posting-Date | 11 Oct 2013 01:06:27 CEST |
| NNTP-Posting-Host | e56fe12b.newsspool2.arcor-online.net |
| X-Trace | DXC=E>bH;n;lHll>jlK2>IgHGdA9EHlD;3Ycb4Fo<]lROoRa8kF<OcfhCOklLE37\F?SNeDZm8W4\YJNlb@mF9jNikde@hR_<@5eU4k3a8LP6i6ZGa |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | csiph.com comp.lang.javascript:21591 |
Show key headers only | View raw
Ben Bacarisse wrote: > Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: >> Ben Bacarisse wrote: >>> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes: >>>> Tony Johansson wrote: >>>>> I want to filter this expression >>>>> http://localhost:49507/slutProjekt/img/TwinBagel.jpg >>> <snip> >>>>> by using regular expression so that I only want the string that starts >>>>> after the last / and end before the dot. >>> <snip> >>> >>>> var s = elmnt.src.replace(/^.*\/([^.]+).*/, '$1'); >>>> >>>> Better: >>>> >>>> var m = (elmnt.src.match(/([^.\/]+)(?:\..*?)?$/) || [])[1]; >>> >>> Not if there is an earlier '.' in the string. >> >> It was not intended as a general solution. > > Oh, OK. That's odd, but it's yours to define "better" as a less general > solution. Using String.prototype.match() is better than String.prototype.replace() here because it is the *direct* solution to the problem of extracting a substring by using pattern matching. >>> I think your first RE will do just as well here, though the trailing .* >>> is no longer needed: >>> >>> var m = (elmnt.src.match(/^.*\/([^.]+)/) || [])[1]; >> >> This is simpler and more general, but less efficient. > > That's interesting. What makes it less efficient? For a start, it has to match almost the entire input when only the last fragment of it is needed. -- 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
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