How to extract text between a phrase and a semicolon using regex -


i have multiple text rows in text file need extract out particular values. have started learning regex , trying hand @ using situation. values extracted digits can either integer or decimal varying decimal places.

two examples of text rows shown below.

settings parametername1 = 15.0; settings parametername2 = 75.0; # increase 25% 50.0; 

the regex string below works first text row not second text row.

(?<=\bsettings.*\=\s).*(?=\;)\b 

the results regex string shown below - second row did not output digit values looking (i.e. expected see 15.0 first row , 75.0 second row , not # comment text).

15.0; 75.0; # increase 25% 50.0; 

many help.

the results regex string shown below

this because .* greedy. when has option stop matching or continue matching, try match many characters possible.

an easy fix add reluctant qualifier ? .* - i.e.

(?<=\bsettings.*\=\s).*?(?=\;)\b 

a better fix replace . [^;], prevent backtracking:

(?<=\bsettings.*\=\s)[^;]*(?=\;)\b 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -