0

I am not very good with Regular Expressions, some times I can figure them out but...

I need to parse text strings (for a chat room project).

So as you would imagine any pasted URLs need to be converted to click-able hyper links.

I use this RegExp for that, cobbled together from examples I have found on the net. It appears to work quite well :

/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:~;@'#%&.=\]\[\*\$\!\?\/\,]+/g

Now another part of my project has to insert images in other words :

<img src="http://path/to/image" alt="alt" />

So I need the reg exp to ignore those, and I tried this :

/(?!src=")[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:~;@'#%&.=\]\[\*\$\!\?\/\,]+/g

But it doesn't work. Perhaps my expression is faulty or I am going about it the wrong way.

I may just mask out 'src="http' and run my expression then reapply what I masked out.

But before I do that I thought I would see if anyone here has any ideas.

Many thanks.

4

1 回答 1

1
(?!src=")

是一个否定的前瞻,你想要的是一个后瞻,这是 javascript 不支持的。

于 2012-06-07T13:51:09.590 回答