Ber53rker
Ber53rker

Reputation: 1038

Match characters prior to word?

I’ve been at it for many hours now and finally decided to give up and ask.

I need a JavaScript Regex to match against things like this:

Basically anything before the word URL except < and >.

I was able to handle characters after the word (below), but not prior. And I need both before and after!

/^(?=\bURL)[^<> ]+$/i

So essentially $B#5t4rg3b4URLDFSGre4r should match and FGWEG$R$G$?>URL<9TGSG should not.

Upvotes: 0

Views: 49

Answers (1)

Anirudha
Anirudha

Reputation: 32797

You should use groups

var myRegexp =/([^<> ]*)URL([^<> ]*)/ig;
var match = myRegexp.exec(input);
alert(match[1]);//before
alert(match[2]);//after

Upvotes: 1

Related Questions