Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Searching up to a specific character

Last post 08-06-2008, 11:02 AM by mash. 3 replies.
Sort Posts: Previous Next
  •  08-06-2008, 9:53 AM 45028

    Searching up to a specific character

    I'm editing an old bookmarks.html file in Dreamweaver to prep it before I import the bookmarks back into Firefox. An example bookmark would look like this:

    <DT><A href="http://isohunt.com/" ADD_DATE="1125111393" LAST_VISIT="1207867025" ICON="data:image/bmp;base64,Qk32AAAAAAAAAHYAAAAoAAAAEAAAABAAAAABAAQAAAAAAIAAAABNEAAATRAAAAAAAAAAAAAAAAAAAAAAgAAAgAAAAICAAIAAAACAAIAAgIAAAICAgADAwMAAAAD/AAD/AAAA//8A/wAAAP8A/wD//wAA////AP8A/////////wD/////////AP////////8A/////////wD//M//zP//AP/8z//M//8A//zP/8z//wD//M//zP//AP/8z//M//8A//zMzMz//wD//MzMzP//AP/8z//M//8A//zP/8z//////M//zP/////8z//M//////zP/8z/" LAST_CHARSET="UTF-8" ID="rdf:#$mk2F01">isoHunt - IRC and Bit Torrent Search Engine</A>

     What I want to do is remove the ICON parameter (in bold) and its associated value. This is the only portion of the tag that I need to find and then use the Replace function to replace it with nothing.

     So far, here's the expression that I have come up with:

     ICON=".*(?!")

    This expression finds the ICON parameter just fine but doesn't stop until it finds the last double-quote before the carriage return. Basically, I need the expression to find ICON=" and then any letter or symbol except for the first double-quote that it encounters regardless of what follows (be it a space or the end of the tag).

    Can someone point out what I'm doing wrong? I'm sure it's pretty simple but, I'm new to regexp. BTW, I'm using RegexBuddy to test.

     

     

  •  08-06-2008, 10:55 AM 45032 in reply to 45028

    Re: Searching up to a specific character

    AUGH! Discovered the solution myself.

    ICON="[^"]+"

    Looks for anything not a quote as many times as possible.

  •  08-06-2008, 11:00 AM 45034 in reply to 45032

    Re: Searching up to a specific character

    Also acceptable, although less-preferred that your solution, would have been ICON=".*?"
  •  08-06-2008, 11:02 AM 45035 in reply to 45028

    Re: Searching up to a specific character

    the dot character match any character except newline.  By default regexes are greedy and try to match as much as possible. So .* will match everything until it encounters a newline.  The negative lookahead only backs up from the end of what has been matched match as far as it needs to, to satisfy that condition meaning the character before the last double quote. Your pattern says "match everything in a line up to the last double quote"

    ICON=\x22[^\x22]*

     


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
View as RSS news feed in XML