#1
  1. Ruby On Rails Junkie
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2003
    Location
    Switzerland
    Posts
    535
    Rep Power
    103

    Find all "<img ...>" Tags that have no trailing slash (".../>")


    Hi all

    I need to make a find and replace within Eclipse. I want to replace all the <img...> tags that miss the needed trailing slash:

    Correct:
    <img .../>

    Wrong:
    <img ...>

    Sadly I haven't done RegEx searching in a while now, and I don't know how to search for characters that must *not* be found...?

    I'd be very thankful for some help, I guess it's quite easy for a pro. :-)

    Thanks
    Josh
    God, you gave man penis and brain, but only enough blood to run one at a time.

    my webpage: www.josh.ch
    my current project: phpmywebmin.josh.ch - a browser based file management application for webspace
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    If Eclipse supports negative lookaheads this should do it: (My primary editor, PS Pad, doesn't. )
    Code:
    <img\b[^>]*(?!\/)>
    Otherwise, you would need to find a tool that does or search for all <img> tags and manually check for the slash.
    Last edited by Kravvitz; January 29th, 2010 at 12:05 PM.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  4. #3
  5. Ruby On Rails Junkie
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2003
    Location
    Switzerland
    Posts
    535
    Rep Power
    103
    Thanks a lot, Kravvitz, helped a lot! :-)
    God, you gave man penis and brain, but only enough blood to run one at a time.

    my webpage: www.josh.ch
    my current project: phpmywebmin.josh.ch - a browser based file management application for webspace
  6. #4
  7. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    I don't believe that will work. The lookahead is zero-width, so it doesn't consume a character. That means you're checking the next character is not a forward slash, while at the same time insisting that it's a closing angle bracket (which is, obviously, not a forward slash). You want a negative lookbehind (if Eclipse supports those):

    Code:
    <img\b[^>]*(?<!/)>
    If it doesn't support lookbehinds, try:
    Code:
    <img\b[^>]*[^>/]>
    That last one won't work on the literal tag "<img>" with no attributes but that's unlikely to occur, I would think.

    Disclaimer: my familiarity of regexps is Perl-based: your implementation may vary.

IMN logo majestic logo threadwatch logo seochat tools logo