1

The end of my expression is the only part causing me problems, im trying to match > not />

something like this: \s*[^\/]> however i dont want to match any other characters before the >

Here is an example, I want this to match any img tags that are not closed.

<img((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\s*[^\/]> 

2 Answers 2

1

Just get rid of the [^\/] at the end, since you only want to match on the >, and no other character:

<img((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\s*> 
Sign up to request clarification or add additional context in comments.

Comments

1
'(<img.*?(?<=[^/])>)' 

positive look-behind checks only for preceding characters. As I understand you only need to check if > is not preceded by \.

As bdukes points out, negative look-behind is another option: (<img.*?(?<!/)>)

4 Comments

This matches the self-closing img tags, I think OP wants to match the non-self-closing tags.
well, one is opposite of the other, no?
Use ?<! instead of ?<= to not match the slash.
I kinda get what you mean, however i only know basic regexp

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.