RegExp: get a match when a string is NOT found

L

Lester

I need a regexp function which makes a match when the string contains
<img...> AND the img tag above dows NOT contain a certain path

Here is what I have:

<img\s.*(src).+>

This matches if my string contains said:
character, the "thisfolder/thatfolde" string can be found, I do NOT need a match. If this string is missing, I DO need a match.

I want to allow users to insert images from a certain path, but prevent
them to insert any images from elsewhere. I dont need replace
functionality, just an alert.

Thank you in advance!
Keke
 
B

Bob Smith

I need a regexp function which makes a match when the string
contains <img...> AND the img tag above dows NOT contain a certain
path

Here is what I have:

<img\s.*(src).+>

This matches if my string contains "<img .....src.....>" (the dots
can be anything, I dont care). However, after the "src" part and
before the > character, the "thisfolder/thatfolde" string can be found, I do
NOT need a match. If this string is missing, I DO need a match.

I want to allow users to insert images from a certain path, but
prevent them to insert any images from elsewhere. I dont need
replace functionality, just an alert.

Something like

<img\s[^>]*?(src\s*=\s*\"(?!thisfolder\/)[^\"]*?\")[^>]*>

should work. The (?!...) term is a negative lookahead. Substitute
the text inside for what you don't want to match.
 
L

Lester

Thank you! This needs some fine tuning for my application (makes a
match in some cases when it shouldn't), but pointed me to the right
direction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top