c# - Regexp Multiline -



c# - Regexp Multiline -

help write right regexp such piece of text.

here needed :

to match strings. key figure id 123. necessary cover set policy id 128 exit

and how place each of string group, because need each row converted kind of

class="lang-none prettyprint-override">set policy id 128 "trust" "untrust" "lm pool" "172.16.2.2/32" "any" permit set policy id 128 set dst-address "miep" set dst-address "miep ws" set dst-address "radius1" set dst-address "radius2" exit

how can supplement creation:

streamreader reader = new streamreader(opendialog.filename); string patternpolicy = @"set policy (id)(.+)exit"; var matchespolicy = regex.matches( reader.readtoend(), patternpolicy, regexoptions.multiline);

you don't need alternative multiline, need regexoptions.singleline:

var matchespolicy = regex.matches(reader.readtoend(), patternpolicy,regexoptions.singleline);

see regular look options:

multiline m utilize multiline mode, ^ , $ match origin , end of each line (instead of origin , end of input string). more information, see multiline mode.

singleline s utilize single-line mode, period (.) matches every character (instead of every character except \n). more information, see singleline mode.

then need create quantifier lazy avoid matching first set policy (id) lastly exit adding ? quantifier:

string patternpolicy = @"set policy (id)(.+?)exit";

another thing is, why putting "id" capturing group? that makes no sense.

string patternpolicy = @"set policy id(.+?)exit";

c# regex

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -