-2

I am dealing with a log line that contains a comma separated value for a particular field -

xyz=,xyz_xyztest_27_jun_2019_2:4000,a_test_case_id-20190624.1:7|431

Logging of these comma separated values may happen in any order. For example -

xyz=,a_test_case_id-20190624.1:7|431,xyz_xyztest_27_jun_2019_2:4000

I am trying to write a regex in perl to match these values -

=~/^(?=.*xyz=)(?=.*xyz_xyztest_27_jun_2019_2:[\da-f]+)(?=.*a_test_case_id-20190624.1:[\da-f]+\|[\da-f]+)/

But this doesn't seem to match. Am I missing something? Thanks

Ira
  • 547
  • 4
  • 13
  • 1
    Your pattern only consists of Lookaheads, meaning that it will only match the empty string (AKA, assert the position) that is followed by everything else. Put the parts that you want to capture in capturing groups: `^(?=.*(xyz=))(?=.*(xyz_xyztest_27_jun_2019_2:[\da-f]+))(?=.*(a_test_case_id-20190624\.1:[\da-f]+\|[\da-f]+))`. Demo: https://regex101.com/r/6OGEa0/1 – 41686d6564 stands w. Palestine Aug 19 '20 at 06:11
  • 1
    You have provided input, what is desired effect you expect from processing input data? – Polar Bear Aug 19 '20 at 06:16
  • Try 2 capturing groups `\G([^\s,=]+)[=:]([^\s,=]*)(?:,|$)` https://regex101.com/r/2zQpBn/1 – The fourth bird Aug 19 '20 at 08:24

1 Answers1

0

OP's question is obscure in nature without sample of desired result/output.

Following code assumes that fields separated with , and variable/value pairs separated with =:

use strict;
use warnings;
use feature 'say';

use Data::Dumper;

while( <DATA> ) {
    chomp;
    my %hash;
    %hash = split "[,=:]";
    say Dumper(\%hash);
}

__DATA__
xyz=,xyz_xyztest_27_jun_2019_2:4000,a_test_case_id-20190624.1:7|431
xyz=,a_test_case_id-20190624.1:7|431,xyz_xyztest_27_jun_2019_2:4000

Output

$VAR1 = {
          'xyz_xyztest_27_jun_2019_2' => '4000',
          'a_test_case_id-20190624.1' => '7|431',
          'xyz' => ''
        };

$VAR1 = {
          'xyz' => '',
          'xyz_xyztest_27_jun_2019_2' => '4000',
          'a_test_case_id-20190624.1' => '7|431'
        };
Polar Bear
  • 6,762
  • 1
  • 5
  • 12