Regular Expression Matching what does NOT match

  • Thread starter Thread starter Earl Teigrob
  • Start date Start date
E

Earl Teigrob

I am parsing some HTML and need to match certain tag attributes to change
from relative to absolute urls.

The search string I am currently using is
rex="src\\s*=\\s*\"(?<content>.+?)\"";

that matches all src attributes on the page (and it works, by the way, but
is doing extra work)

However, I really do not need to match attributes that where the address
starts with "http://"

Of course to match all occurances of this "http://" is quite easy by using

rex="src\\s*=\\s*\"(?<content>http://.+?)\"";

BUT

What about just the opposite? How can I match all occurances of the src
attribute where the url DOES NOT start with "http://"?

Something like

rex="src\\s*=\\s*\"(?<content>[^(http://)].+?)\""; //DOES NOT WORK

or can this be done???

Earl
 
I got this figured out after reading my book on regular expression by using
the LookAround functions. Works perfectly...

Earl
 

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

Back
Top