Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #7699
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed101.telia.com!starscream.dk.telia.net!news.tele.dk!feed118.news.tele.dk!not-for-mail |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Regular expression question |
| References | <a9fa509f-5f3c-4926-abc6-c77a21427d8f@j36g2000prh.googlegroups.com> |
| From | Lasse Reichstein Nielsen <lrn.unread@gmail.com> |
| Date | Wed, 26 Oct 2011 19:33:06 +0200 |
| Message-ID | <mxcnirot.fsf@gmail.com> (permalink) |
| User-Agent | Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Rational FORTRAN, windows-nt) |
| Cancel-Lock | sha1:FgmvrpCtnuRXYI2ou4ZtixN1c9M= |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Lines | 30 |
| Organization | TDC Totalloesninger |
| NNTP-Posting-Host | 87.57.52.80 |
| X-Trace | 1319650387 dtext01.news.tele.dk 281 87.57.52.80:49965 |
| X-Complaints-To | abuse@post.tele.dk |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.javascript:7699 |
Show key headers only | View raw
cerr <ron.eggler@gmail.com> writes:
> First thing, I'm a regular expression newbie.... somewhat anyways...
> I would like to recognize the difference between this url:
> http://quaaoutlodge.com/site/the-lodge/our-history.html
> and that url:
> http://quaaoutlodge.com/site/the-lodge.html
> and at the same time extract the document name (our-history or the-
> lodge) and the directory name if present (the-lodge).
> I got stuck at how rto rcognize the second directory instead of the
> first (the-lodge/ instead of site/) with "\b\/[a-z]+\/" how do i get
> the second one only?
When you think a RegExp might solve your problem - stop for a moment
and think whether there is also a simpler solution :)
In this case, I'd just do:
function name(url) {
var name_end = url.lastIndexOf(".");
var name_start = url.lastIndexOf("/", name_end) + 1;
return url.substr(name_start, name_end);
}
If your URLs aren't always that simple, you'd need to adapt a RegExp too.
/L
--
Lasse Reichstein Holst Nielsen
'Javascript frameworks is a disruptive technology'
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Regular expression question cerr <ron.eggler@gmail.com> - 2011-10-25 21:43 -0700
Re: Regular expression question Mike Duffy <never@you.mind.com> - 2011-10-26 12:11 +0000
Re: Regular expression question Denis McMahon <denismfmcmahon@gmail.com> - 2011-10-26 16:54 +0000
Re: Regular expression question Lasse Reichstein Nielsen <lrn.unread@gmail.com> - 2011-10-26 19:33 +0200
Re: Regular expression question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-26 23:40 +0200
Re: Regular expression question Antony Scriven <adscriven@gmail.com> - 2011-10-27 17:30 -0700
Re: Regular expression question Antony Scriven <adscriven@gmail.com> - 2011-10-27 17:39 -0700
Re: Regular expression question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-28 03:50 +0200
Re: Regular expression question Antony Scriven <adscriven@gmail.com> - 2011-10-28 08:46 -0700
Re: Regular expression question Lasse Reichstein Nielsen <lrn.unread@gmail.com> - 2011-10-28 18:50 +0200
Re: Regular expression question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-28 19:50 +0200
Re: Regular expression question Antony Scriven <adscriven@gmail.com> - 2011-10-28 11:41 -0700
Re: Regular expression question Antony Scriven <adscriven@gmail.com> - 2011-10-28 12:54 -0700
Re: Regular expression question Dr J R Stockton <reply1143@merlyn.demon.co.uk> - 2011-10-27 19:41 +0100
Re: Regular expression question Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-28 04:12 +0200
csiph-web