recognising a special character inside [^]

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

  1. #1

    Default recognising a special character inside [^]

    Hi

    What I need to do is to print only '1|2|3'.

    #----------------------------------------------------------------
    @array = (
    '1',
    '1|2',
    '1|2|3',
    '1|2|3|4',
    '1|2|3|4|5',
    '1|2|3|4|5|6'
    );

    $string = '1|2';

    foreach (@array)
    {
    if ($_ =~ /^$string\|([^\|]*)$/)
    {
    print "$_\n";
    }
    }
    #----------------------------------------------------------------

    But the above code prints the entire array out.

    I believe the problem lies with ([^\|]*).

    How do I correctly tell Perl to recognise the pipe | character inside
    ([^\|]*)

    Any help would be appreciated.




    Jason Q.
    Jason Quek Guest

  2. Similar Questions and Discussions

    1. MX 7 and CGI special character problem
      The umlauts have stopped working in our application since upgrading to Coldfusion MX 7 and Apache 2.0.43. A html form is sent to coldfusion. A...
    2. how to query a column name with special character
      i was able to create a table with a column name abc\ on db2 v8.1 on windows, but when i do the query select abc\ from table, i get error '\' is...
    3. Special Character search lik
      How did u insert mycafé in database ?? Use same client settings which u used for insert. Hope this helps. ( Else post ur settings or method to...
    4. Special character for SM?
      Hi all, I need to insert the character "SM", similar to special character "TM". Is there a keystroke for this like TM? Would rather use htm text...
    5. I need a special character....
      The a in Mangels need an umlaut, please. Eleanor
  3. #2

    Default Re: recognising a special character inside [^]


    "Jason Quek" <qjason@cyberway.com.sg> wrote in message
    news:3f66b174.7039109@news.starhub.net.sg...
    > Hi
    >
    > What I need to do is to print only '1|2|3'.
    >
    > #----------------------------------------------------------------
    > @array = (
    > '1',
    > '1|2',
    > '1|2|3',
    > '1|2|3|4',
    > '1|2|3|4|5',
    > '1|2|3|4|5|6'
    > );
    >
    > $string = '1|2';
    >
    > foreach (@array)
    > {
    > if ($_ =~ /^$string\|([^\|]*)$/)
    > {
    > print "$_\n";
    > }
    > }
    > #----------------------------------------------------------------
    >
    > But the above code prints the entire array out.
    >
    > I believe the problem lies with ([^\|]*).
    >
    > How do I correctly tell Perl to recognise the pipe | character inside
    > ([^\|]*)
    >
    > Any help would be appreciated.
    if ($_ =~ /^\Q$string\E\|([^\|]*)$/) {
    ....
    }

    --
    Brian Wakem


    Brian Wakem Guest

  4. #3

    Default Re: recognising a special character inside [^]

    Jason Quek <qjason@cyberway.com.sg> wrote:
    > $string = '1|2';

    vertical bars are special in a regex, you must backslash them
    if you want a literal one:

    my $string = '1\|2';


    > I believe the problem lies with ([^\|]*).

    Nope.


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan 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