Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <4522206.f2d4svmm8S@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Thu, 10 Oct 2013 22:57 +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+&. <1692823.iOv17HgRNK@PointedEars.de> <0.59968aeff2274c0aa6ab.20131010213157BST.8738o827gi.fsf@bsb.me.uk> MIME-Version: 1.0 Lines: 33 NNTP-Posting-Date: 10 Oct 2013 22:57:05 CEST NNTP-Posting-Host: 2ea5db22.newsspool2.arcor-online.net X-Trace: DXC=IWecVUV2;HLX36K@\WTHGJA9EHlD;3YcB4Fo<]lROoRA8kF Thomas 'PointedEars' Lahn writes: >> Tony Johansson wrote: >>> I want to filter this expression >>> http://localhost:49507/slutProjekt/img/TwinBagel.jpg > >>> by using regular expression so that I only want the string that starts >>> after the last / and end before the dot. > > >> 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. > 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. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.