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

Re: [PBML] Detecting Overlapping Patterns

Expand Messages
  • Jenda Krynicky
    From: Debaprasad Mukherjee ... You have to change the position where the regexp engine starts next time it looks for a match: $x =
    Message 1 of 2 , Feb 25, 2006
    • 0 Attachment
      From: "Debaprasad Mukherjee" <devprozad@...>
      > Dear Friends,
      > I want to write a script that will dtecet overlapping patterns. e.g.
      > Say I want to detect the pattern CC in my string. Now if my string is
      > something like CCCCC, I would like mmy script to detect all the 4 CC
      > patterns. How can I do this?
      >
      > Deb

      You have to change the position where the regexp engine starts next
      time it looks for a match:

      $x = "abcdef";
      while($x =~ /\G(..)/) {
      print "MATCH: $1\n";
      pos($x) = $-[0]+1;
      };


      The \G matches (under normal circumstances) wherever the last match
      ended, the $[0] contains the position of the start of the last match.
      So you want to change the position to one character after the start
      of the last match.

      See
      perldoc -f pos
      perldoc perlvar
      perldoc perlre

      HTH, Jenda

      ===== Jenda@... === http://Jenda.Krynicky.cz =====
      When it comes to wine, women and song, wizards are allowed
      to get drunk and croon as much as they like.
      -- Terry Pratchett in Sourcery
    Your message has been successfully submitted and would be delivered to recipients shortly.