Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Regular Expression - how do I parse this?

Expand Messages
  • merlyn@stonehenge.com
    ... Victor given: Victor $line = callUuid= 92b2be68-94af-11da-c59b-00e08101a72a Victor callerId= 6304751054 date= 2006-02-03
    Message 1 of 5 , Mar 2, 2006
    • 0 Attachment
      >>>>> "Victor" == Victor Bouffier <victor@...> writes:

      Victor> given:
      Victor> $line = <CallReceivedEvent
      Victor> callUuid="92b2be68-94af-11da-c59b-00e08101a72a"
      Victor> callerId="6304751054" date="2006-02-03 07:21:18" id="34A3D196-441F-
      Victor> 258C-67F9-F5552D101D94"/>;

      Victor> then executing

      Victor> if $line =~ /^<(\w+).+?callUuid="(.+?)".+?date="(.+?)".+?\bid="(.+?)"/ {
      Victor> $event_type = $1;
      Victor> $calluuid = $2;
      Victor> $date = $3;
      Victor> $id = $4;
      Victor> }

      Victor> gives you your variables.
      Victor> Each parenthesis groups a consecutive numbered variable.
      Victor> I believe it would work even if the variables where not in that same
      Victor> order, except for event_type, which should be the first one.

      Nope, you used "." which won't match across newlines.

      Don't use a regex. Use an XML parser.

      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    • Victor Bouffier
      Right. XML::Simple would do, I guess? Now, XML::Simple would parse all internals between the opening and closing tags, but you still need the /^
      Message 2 of 5 , Mar 2, 2006
      • 0 Attachment
        Right.
        XML::Simple would do, I guess?

        Now, XML::Simple would parse all internals between the opening and
        closing tags, but you still need the /^<(\w+)/ regex to capture the
        event_type, don't you?

        Anyway, I stand corrected.

        On Thu, 2006-03-02 at 21:00 -0800, merlyn@... wrote:
        > >>>>> "Victor" == Victor Bouffier <victor@...> writes:
        >
        > Victor> given:
        > Victor> $line = <CallReceivedEvent
        > Victor> callUuid="92b2be68-94af-11da-c59b-00e08101a72a"
        > Victor> callerId="6304751054" date="2006-02-03 07:21:18" id="34A3D196-441F-
        > Victor> 258C-67F9-F5552D101D94"/>;
        >
        > Victor> then executing
        >
        > Victor> if $line =~ /^<(\w+).+?callUuid="(.+?)".+?date="(.+?)".+?\bid="(.+?)"/ {
        > Victor> $event_type = $1;
        > Victor> $calluuid = $2;
        > Victor> $date = $3;
        > Victor> $id = $4;
        > Victor> }
        >
        > Victor> gives you your variables.
        > Victor> Each parenthesis groups a consecutive numbered variable.
        > Victor> I believe it would work even if the variables where not in that same
        > Victor> order, except for event_type, which should be the first one.
        >
        > Nope, you used "." which won't match across newlines.
        >
        > Don't use a regex. Use an XML parser.
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.