...

View Full Version : Requesting a RegExp...



AaronW
10-05-2003, 04:13 PM
I posted something pretty much the same in the "server side" forum, but realised that the JS folks might have more experience with this:

I'm simply looking to match "wordhere/" (ignore all my double quotes) where "wordhere" does not equal "admin" or "register". So this would be something like:

[^(admin|register)]+[\/]?

The trailing slash may or may not be there.

EDIT: Oh, and the "wordhere" needs to be captured. That's the trouble right there. Capturing the bugger is proving difficult.

Anyway, this doesn't work. Any ideas?

Thanks a whole heap in advance.

Jeff Mott
10-05-2003, 06:26 PM
/^(?!admin|register)(.*)\/$/i

liorean
10-05-2003, 07:20 PM
Negative lookaheads are not the best supported feature of JS regexes. Why not do a two-stage confirmation instead?
var
r=(/^(admin|register)/i).test([string path])?
null:
(/^([^\/])/i).match([string path]);

AaronW
10-05-2003, 09:41 PM
Yeah, I went with liorean's approach.

I got really close with a few of my own. Annoying that something this easy took me so long :o



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum