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

  1. #1

    Default Regex..

    Could some good samaritan help me out with this pls...

    I am trying to find a regular expression for the below string..

    ExchangeName = MOLD%20WEST
    ExpectedDate = ZZZZZZZZ
    LineStatus = Z
    Status = NO
    200 OK -

    and i am trying with something as below:
    $line =~ /([a-zA-Z_0-9.]+)\s*=\s*([a-zA-Z_0-9.]+)/;

    I am able to fix the first three lines; but the last line (200 OK - )
    is giving me problems...

    I also tried.

    $line =~ /([a-zA-Z_0-9.]+)\s*=\-\s*([a-zA-Z_0-9.]+)/;

    but it gives me an error as i m trying put the above values in a hash.

    ----------------------------------------------------------------------------
    ----------------

    regards,

    Ajitpal Singh,
    Ajit P Singh Guest

  2. Similar Questions and Discussions

    1. Regex help
      I'd like to replace any html tags containing "< >" with a space. For example, <TR VALIGN=TOP>, I'd like to replace that with a space. Is there a...
    2. REGEX help pls
      in the regex buddy they are explaining: "Be careful when using the negated shorthands inside square brackets. is not the same as . The latter...
    3. regex, is this possible?
      Hi! I am trying to break down the following: printf("numsteps=%d i=%d im=%g vfr=%g \n",numsteps,i,imeas,vforce); into "numsteps= numsteps ...
    4. Need help with regex
      > I have a directory of files that I want to move to another directory.
    5. IP regex?
      Gareth Glaccum wrote: How about using m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ and testing $1 - $4 for compliance? Much cleaner. -- Cheers,
  3. #2

    Default Re: Regex..

    Ajit P Singh wrote:
    >
    > Could some good samaritan help me out with this pls...
    >
    > I am trying to find a regular expression for the below string..
    >
    > ExchangeName = MOLD%20WEST
    > ExpectedDate = ZZZZZZZZ
    > LineStatus = Z
    > Status = NO
    > 200 OK -
    >
    > and i am trying with something as below:
    > $line =~ /([a-zA-Z_0-9.]+)\s*=\s*([a-zA-Z_0-9.]+)/;
    >
    > I am able to fix the first three lines; but the last line (200 OK - )
    > is giving me problems...
    >
    > I also tried.
    >
    > $line =~ /([a-zA-Z_0-9.]+)\s*=\-\s*([a-zA-Z_0-9.]+)/;
    >
    > but it gives me an error as i m trying put the above values in a hash.
    Hi Ajit.

    I'm not clear what result you want for the last line, but this should help.

    Cheers,

    Rob



    use strict;
    use warnings;

    while (<DATA>) {
    if (/(.*?)\s*-/) {
    printf "\$1 = %s\n", $1;
    }
    elsif (/([^\s=]+).*?([^\s=]+)/) {
    printf "\$1 = %-14s \$2 = %s\n", $1, $2;
    }
    }

    __DATA__
    ExchangeName = MOLD%20WEST
    ExpectedDate = ZZZZZZZZ
    LineStatus = Z
    Status = NO
    200 OK -

    **OUTPUT

    $1 = ExchangeName $2 = MOLD%20WEST
    $1 = ExpectedDate $2 = ZZZZZZZZ
    $1 = LineStatus $2 = Z
    $1 = Status $2 = NO
    $1 = 200 OK


    Rob Dixon 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