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

  1. #1

    Default undo the (?i)

    Hi all,

    I have an RE where I use the (?i) somewhere, but I want to undo that effect
    further on in the RE.
    Here's an example:

    $var="(?i)(forty|fifty)";
    $input = "Forty-ninth ST";
    if ($input =~ /$var(\-ninth)\s[S|s]t/) {
    print "$&\n";
    }

    Because the $var contains the (?i), it matches the rest of the RE
    case-insensitively, but I want
    to match everything after the $var case-sensitively. Can I escape the ($i)
    or set the scope of it?

    Thanks,

    J


    joeri Guest

  2. Similar Questions and Discussions

    1. undo highlighting in AA 5.0
      hi all, received a pdf from a client, that received it from his client, with yellow highlighting in certain sections. he would like to "undo" that...
    2. ID CS2: can't undo
      Help! We have a file open in indesign that has not been saved in a while, a large amount of work has just been deleted but we cannot 'undo'. Apple-Z...
    3. Undo Levels?
      It seems there is only one level of "undo" in Director MX 2004 (mac). I've searched the preferences and help files and cannot seem to find any...
    4. undo bitmap?
      Hi, is there any way to "undo" an image after I flattened/saved it to bitmap? (undo CNTL + Z not an option - too late for that) Thanks. John
    5. Undo in TextBox
      Hi, If a user enters a wrong value (which depends on some properties of it's container control) in one of my dynamicly made TextBoxes I want to...
  3. #2

    Default Re: undo the (?i)

    Also sprach joeri:
    > I have an RE where I use the (?i) somewhere, but I want to undo that effect
    > further on in the RE.
    > Here's an example:
    >
    > $var="(?i)(forty|fifty)";
    > $input = "Forty-ninth ST";
    > if ($input =~ /$var(\-ninth)\s[S|s]t/) {
    > print "$&\n";
    > }
    >
    > Because the $var contains the (?i), it matches the rest of the RE
    > case-insensitively, but I want
    > to match everything after the $var case-sensitively. Can I escape the ($i)
    > or set the scope of it?
    You can again turn it off at some point:

    $input =~ /$var(?-i)(-ninth)\s[S|s]t/;

    So, -i will prevent case-insensitive matching for the patterns right of
    it.

    Tassilo
    --
    $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
    Tassilo v. Parseval Guest

  4. #3

    Default Re: undo the (?i)

    Also sprach joeri:
    > Tassilo v. Parseval wrote:
    >
    >> > I have an RE where I use the (?i) somewhere, but I want to undo
    >> > that effect further on in the RE.
    >> > Here's an example:
    >> >
    >> > $var="(?i)(forty|fifty)";
    >> > $input = "Forty-ninth ST";
    >> > if ($input =~ /$var(\-ninth)\s[S|s]t/) {
    >> > print "$&\n";
    >> > }
    >> >
    >> > Because the $var contains the (?i), it matches the rest of the RE
    >> > case-insensitively, but I want to match everything after the $var
    >> > case-sensitively. Can I escape the ($i) or set the scope of it?
    >>
    >> You can again turn it off at some point:
    >>
    >> $input =~ /$var(?-i)(-ninth)\s[S|s]t/;
    >>
    >> So, -i will prevent case-insensitive matching for the patterns right of
    >> it.
    > Thanks! I couldn't find it in the docs or google.
    You'll find it in perlre.pod under "Extended patterns":

    "(?imsx-imsx)"
    One or more embedded pattern-match modifiers, to be turned on
    (or turned off, if preceded by "-") for the remainder of the
    pattern or the remainder of the enclosing pattern group (if
    any). [...]

    It can indeed be easily overlooked.

    Tassilo
    --
    $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
    Tassilo v. Parseval Guest

  5. #4

    Default Re: undo the (?i)


    Tassilo v. Parseval wrote:
    > Also sprach joeri:
    >
    > > Tassilo v. Parseval wrote:
    > >
    > >> > I have an RE where I use the (?i) somewhere, but I want to undo
    > >> > that effect further on in the RE.
    > >> > Here's an example:
    > >> >
    > >> > $var="(?i)(forty|fifty)";
    > >> > $input = "Forty-ninth ST";
    > >> > if ($input =~ /$var(\-ninth)\s[S|s]t/) {
    > >> > print "$&\n";
    > >> > }
    > >> >
    > >> > Because the $var contains the (?i), it matches the rest of the RE
    > >> > case-insensitively, but I want to match everything after the $var
    > >> > case-sensitively. Can I escape the ($i) or set the scope of it?
    > >>
    > >> You can again turn it off at some point:
    > >>
    > >> $input =~ /$var(?-i)(-ninth)\s[S|s]t/;
    > >>
    > >> So, -i will prevent case-insensitive matching for the patterns right of
    > >> it.
    >
    > > Thanks! I couldn't find it in the docs or google.
    >
    > You'll find it in perlre.pod under "Extended patterns":
    >
    > "(?imsx-imsx)"
    > One or more embedded pattern-match modifiers, to be turned
    on
    > (or turned off, if preceded by "-") for the remainder of the
    > pattern or the remainder of the enclosing pattern group (if
    > any). [...]
    >
    > It can indeed be easily overlooked.
    >
    Here's what my 5.6 docs say. It is indeed there, but I overlooked it...

    (?imsx-imsx)
    One or more embedded pattern-match modifiers. This is particularly useful
    for dynamic patterns, such as those read in from a configuration file, read
    in as an argument, are specified in a table somewhere, etc. Consider the
    case that some of which want to be case sensitive and some do not. The case
    insensitive ones need to include merely (?i) at the front of the pattern.
    For example:
    $pattern = "foobar";
    if ( /$pattern/i ) { } # more flexible: $pattern = "(?i)foobar";
    if ( /$pattern/ ) { }Letters after a - turn those modifiers off.

    J


    joeri Guest

  6. #5

    Default Re: undo the (?i)

    "joeri" <jvandervloet@hotmail.com> writes:
    > $var="(?i)(forty|fifty)";
    > $input = "Forty-ninth ST";
    > if ($input =~ /$var(\-ninth)\s[S|s]t/) {
    > print "$&\n";
    > }
    > Can I escape the ($i) or set the scope of it?
    /(?:$var)(\-ninth)\s[S|s]t/


    --
    \\ ( )
    . _\\__[oo
    .__/ \\ /\@
    . l___\\
    # ll l\\
    ###LL LL\\
    Brian McCauley Guest

  7. #6

    Default Re: undo the (?i)

    joeri wrote:
    >
    > I have an RE where I use the (?i) somewhere, but I want to undo that effect
    > further on in the RE.
    > Here's an example:
    >
    > $var="(?i)(forty|fifty)";
    Change that to:

    $var = '(?i:forty|fifty)';

    Which will limit the effects of case insensitivity to the enclosing
    parenthesis.

    > $input = "Forty-ninth ST";
    > if ($input =~ /$var(\-ninth)\s[S|s]t/) {
    ^^^^^
    Your character class is trying to match a 'S' or a '|' or a 's'. Do you
    really want to match a vertical bar here? The hyphen is not special in
    regular expressions, there is no need to backslash it.

    > print "$&\n";
    > }

    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn 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