in reply to Regex not matching &

Well, you require the match to start with a switch between word and non-word characters. However, both a space and a & are non-word characters. So you fail to match "words" starting with an ampersand.

I'm not giving you an alternate regexp, as it isn't quite clear to me what exactly you consider to be a word or not.

Abigail

Replies are listed 'Best First'.
Re: Re: Regex not matching &
by murugu (Curate) on Mar 18, 2004 at 15:57 UTC

    Actually what we are doing is we have two files. File 1 is an XML file. File 2 is a text file which consist of words with hyphenations.

    FILE-I

    <element id="10">&alpha;phenol-acetate and Ace-tone and 5-ethyl-alcohol</element>

    File-II

    Ace-tone

    &alpha;phenol-acetate

    I want to replace the hyphenated words present in file1 which is also present in file2 with hyphens changed into <->.

    is the problem is now clear

    we want the regular expression

    thanks for ur kind reply

      Eh, no. The problem is not clear. Any problem that considers matching "words" isn't clear unless there is a clear (sic) definition of what a word is. Your original code allows "words" to contain semi-colons, dashes and ampersands. Are you considering ;-; to be a word? Is father-in-law&mother-in-law one or two words? Etc, etc.

      Once you have a clear definition of what you are going to consider words, writing a regex is likely to be easy.

      Abigail