Pattern Match Question..

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

  1. #1

    Default Pattern Match Question..

    I want to replace all instances of the combination of \" with \"

    Using the Regex code below, I end up replacing ALL " with &guot; and all
    \" with \&guot;
    How can I make it ONLY replace the combination of \" ?

    $TextBlockToConvert =~ s/\"/\quot;/g;

    NOTE:
    The combination of \" may or may not have other characters butting up
    against either or both sides of it.


    Thanks,
    --
    ....
    `·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney


    Rodney Guest

  2. Similar Questions and Discussions

    1. pattern match
      Where can I find infi or doc on "pattern match" used within WHERE clause (mysql). As I need to matche with PHP variables I'd prfer something...
    2. [ADMIN] Pattern Match
      It was Wednesday, December 10, 2003 when Rob Dixon took the soap box, saying: : Before I finally burst my cyanide capsule, may I.. ? No, you may...
    3. please help !! pattern match
      Hi , I need some help me to extract a pattern. The delimiters is a pair of "abcd" and "efgh". Can some one help me with an efficient use of Greedy...
    4. uninitialized value in pattern match
      #!/usr/bin/perl use warnings; use strict "refs"; use strict "subs"; use strict "vars"; our $netscape; $netscape = ($ENV{HTTP_USER_AGENT}...
    5. Pattern match with 2 conditions
      Stephan Bour <sbour@niaid.nih.gov> writes: use strict; # is your friend what's the point of this when you just set it back to "" below? ...
  3. #2

    Default Re: Pattern Match Question..

    Rodney wrote:
    >
    > I want to replace all instances of the combination of \" with \&quot;
    >
    > Using the Regex code below, I end up replacing ALL " with &guot; and all
    > \" with \&guot;
    > How can I make it ONLY replace the combination of \" ?
    >
    > $TextBlockToConvert =~ s/\"/\quot;/g;
    The backslash character is special in double quoted strings so you have
    to escape it if you want a literal backslash character.

    $TextBlockToConvert =~ s/\\"/&quot;/g;



    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn Guest

  4. #3

    Default Re: Pattern Match Question..

    John W. Krahn graced us by uttering:
    > Rodney wrote:
    > > I want to replace all instances of the combination of \"
    > > with \&quot;
    > >
    > > Using the Regex code below, I end up replacing ALL " with
    > > &guot; and all \" with \&guot; How can I make it ONLY
    > > replace the combination of \" ?
    > >
    > > $TextBlockToConvert =~ s/\"/\quot;/g;
    What this actually does is change all <"> to <&quot;>; the <\> is
    ignored.
    > The backslash character is special in double quoted strings so
    > you have to escape it if you want a literal backslash
    > character.
    >
    > $TextBlockToConvert =~ s/\\"/&quot;/g;
    The left side is right, but I think the OP wanted a <\> in his
    result as well. If that's the case, the following will work:

    $block_to_cnvt =~ s#\\"#\\&quot;#g;

    or

    # uses capturing parens to reduce
    # ambiguity in replacement string
    $block_to_cnvt =~ s#(\\)"#$1&quot;#g;

    HTH,
    Tim Hammerquist
    --
    Last year in Oregon, Summer fell on a *tuesday*.
    That was it. One day. Big shiny thing in the sky.
    Some people thought it was a UFO.
    -- Randal L. Schwartz, comp.lang.perl.misc
    Tim Hammerquist Guest

  5. #4

    Default Re: Pattern Match Question..

    That did it perlfectly!

    Thanks John.
    --
    ....
    `·.¸¸.·´¯`·.¸¸.·´¯`·-> rodney


    Rodney 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