regex - Regular Expression: search multiple string with linefeed delimited by ";" -


i have string such described structured data source:

 header whocares;  sampletestplan 2    b    c d;  test abc;  sampletestplan 3    e f    g h    l;   wafer 01;   endoffile; 

every field... ... starting "fieldname" ... ending ";" ... may contain linefeed

my need find regular expression values of sampletestplan that's repeated twice. so... 1st value is:

     2    b    c d 

2nd value is

     3    e f    g h    l 

i've performed several attempts such search string:

/sampletestplan(.\s)/gm

/sampletestplan(.\s);/gm

/sampletestplan(.*);/gm

but need understand better how regular expression work i'm definitively newbie on them , need learn lot.

thanks in advance may me!

stefano, milan, italy

you use following regex:

(?<=\w\b)[^;]+(?=;) 

see working live here on regex101!


how works:
matches is:

  • preceded sequence of characters: \w+
  • followed ;
  • contains (at least 1 character) except ; (including newlines).

for example, input:

 header whocares;  sampletestplan 2    b    c d;  test abc;  sampletestplan 3    e f    g h    l;   wafer 01;   endoffile; 

it matches 5 times:

whocares 

then:

     2      b      c d 

then:

abc 

then:

     3      e f      g h      l 

then:

01 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -