tags:

views:

220

answers:

2

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*[^\/]>
+1  A: 

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*>
bdukes
doh! thanks bdukes
Alan
+1  A: 
'(<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.*?(?<!/)>)

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