homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

regex for correcting &
matching only a single &

5+ Year Member

Msg#: 4508908 posted 3:46 pm on Oct 17, 2012 (gmt 0)

trying to cleanup some loose '&'s with &#38:
thought a find and replace using \s&\s and replacing with &#38 would do the trick. So a single & identified by a space either side. But when i try this in espresso and other regex software it doesnt match. Dont understand why. Any help?



WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4508908 posted 11:09 pm on Oct 17, 2012 (gmt 0)

Do you mean it never matches, or it only sometimes matches?

When you say &#38 I hope you mean & with closing semicolon. Most browsers will display it without, but it isn't formally correct. fwiw, I always use &

If you're adding html markup to existing text, it is definitely easier to do ampersands before anything else at all. Then you can just replace them globally. (I'm speaking from an e-books perspective.)

It doesn't matter what comes before the &. You have to look at what comes after it-- and that depends on what state your text is in. A lookahead may be the best approach:
&(?!#|mdash;|amp;) and so on.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved