backtracking in regular expression matching

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default backtracking in regular expression matching

    Hi,
    For the pattern "(((.*)cd)*)*cdcd" and string "ababcdcdcdef", can
    anyone tell me the detail meachanism of backtracking? This regular
    expression have two level of backtracking, the "((.*)cd)*" and
    "(((.*)cd)*)*", so which one take precedence?
    Thanks.
    ccwork Guest

  2. Similar Questions and Discussions

    1. Regular expression help
      Hi, I'm pretty new to regular expressions. Before, I used to write long-winded and buggy segments of code with PHPs string functions to extract...
    2. regular expression help..
      On Thu, 28 Aug 2003 15:50:49 +0200 "point" <point@caanNOSPAMproduction.com> wrote: Don't cross post, it's considered bad form. /^-+$/ ...
    3. split() matching regular expression question - openwebmail bug...
      Openwebmail seems to have a bug in the way it stores and retrieves data, especially passwords from a file called .pop3book. In .pop3book there...
    4. Regular Expression Help please
      All, I have this regular expression which a guy here provided yesterday, this regexp parses an executable name from a log file, however it only...
    5. Regular Expression Matching
      Hello, I am trying to figure out how to match a an email w/in a delimited line. ie: 1, 'John', 'Doe', 'I', 'john.doe@domain.ext' the list...
  3. #2

    Default Re: backtracking in regular expression matching

    On 16 Sep 2003 03:14:01 -0700, ccwork <ccwork@hotmail.com> wrote:
    > Hi,
    > For the pattern "(((.*)cd)*)*cdcd" and string "ababcdcdcdef", can
    > anyone tell me the detail meachanism of backtracking? This regular
    > expression have two level of backtracking, the "((.*)cd)*" and
    > "(((.*)cd)*)*", so which one take precedence?
    Matching occurs starting at the left, each "element" being greedy (unless
    specified otherwise with ?). Backtracking occurs when a match fails.

    You have a '**' construct in the regex which will cause *large* amounts
    of backtracking, since it leads to *lots* of ways of matching the same
    string (even worse there's a .* inside that as well).

    But it works from the left greedily, at each step. With backtracking
    occuring when some part of the expression can't match. The backtracking
    causes the previous greedy expression to match fewer characters (with
    non-greedy expressions it would match more...).

    --
    Sam Holden

    Sam Holden Guest

  4. #3

    Default Re: backtracking in regular expression matching

    On 16 Sep 2003 03:14:01 -0700
    [email]ccwork@hotmail.com[/email] (ccwork) wrote:

    # Hi,
    # For the pattern "(((.*)cd)*)*cdcd" and string "ababcdcdcdef", can
    # anyone tell me the detail meachanism of backtracking? This regular
    # expression have two level of backtracking, the "((.*)cd)*" and
    # "(((.*)cd)*)*", so which one take precedence?

    You can use the 're' module to throw some more debug information to
    you.

    use re qw /debug/;
    -- or --
    use re qw /debugcolor/; # same with colored output

    see perldoc re for more details.

    Regards,
    Thens.

    Thens Guest

  5. #4

    Default Re: backtracking in regular expression matching

    Hi,
    But how to interpret the 500 lines output? Any website recommended?
    Thanks.
    "Thens" <thens@NOSPAMti.com>
    ???????:20030916174054.5c20a7b0.thens@NOSPAMti.com ...
    > On 16 Sep 2003 03:14:01 -0700
    > [email]ccwork@hotmail.com[/email] (ccwork) wrote:
    >
    > You can use the 're' module to throw some more debug information to
    > you.
    >
    > use re qw /debug/;
    > -- or --
    > use re qw /debugcolor/; # same with colored output
    >
    > see perldoc re for more details.
    >
    > Regards,
    > Thens.
    >

    ccwork Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139