Loading ...
Sorry, an error occurred while loading the content.

Re: need help with regex doing a ^!Replace command

Expand Messages
  • m_frascinella
    Sheri, Aha, now I get it. Every character is loaded with meaning. Now that I see it explained piece by piece, I see how the search pattern is built and
    Message 1 of 5 , Nov 14, 2007
    • 0 Attachment
      Sheri,

      Aha, now I get it. Every character is loaded with meaning. Now that I
      see it explained piece by piece, I see how the search pattern is built
      and replaced. Thanks for the example and for the detailed explanation.
      It goes a long way in enabling me to understand how to use regex.

      For safe keeping, I put your explanation inside the clip that uses it
      (for handy reference).

      Thanks.

      Michael F.


      --- In ntb-clips@yahoogroups.com, "Sheri" <silvermoonwoman@...> wrote:
      > Hi Michael,
      >
      > When a character class (i.e., characters in square brackets) start
      > with a ^ it has a different meaning. It negates the character class.
      > That means, all characters except for the ones in the character class.
      > In the above, [^\r\n] says any character except a carriage return or
      > line feed. The plus outside the character class makes it match
      > multiple such characters. The parentheses around that puts the part
      > that matches that subpattern into substring 1, which can be extracted
      > in the replacement text with $1. After that subpattern, it matches a
      > carriage return followed by a line feed followed by zero or more
      > spaces followed by <br>. Then it matches multiples of characters that
      > are not left angle bracket, carriage return or linefeeds and captures
      > them as substring 2.
      >
      > You could put a ^ at the start of the pattern, it might be more
      > optimized because then it would be considered anchored, e.g.:
      >
      > ^([^\r\n]+)\r\n *<br>([^<\r\n]+)
      >
      > Regards,
      > Sheri
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.