c# 4.0 - How to match multiple lines words using regex expression -
as title describled,i want match multiple lines words regex expression begin "no" , end "e".here sample below:
special instructions
no
t fo
r c
us
tom
er
sig
na
tur
e
table of contents
customer details 1
site details 2
tom tom sales b.v. german branch 2
dynamic bandwidth 6
billing details 7
what want this:
special instructions
table of contents
customer details 1
site details 2
tom tom sales b.v. german branch 2
dynamic bandwidth 6
billing details 7
any appreciated.
you can use pattern multiline and singleline options:
@"^no\r?\n.*?^e\r?\n" example:
regex rgx = new regex(@"^no\r?\n.*?^e\r?\n", regexoptions.multiline|regexoptions.singleline); string result = rgx.replace(yourstr, ""); pattern description:
^ # anchor start of line (because multiline option # used, otherwise ^ anchor start of string) no \r?\n # optional carriage return , line feed .*? # characters 0 or more times (the dot can match newlines since # singleline option used, dot can't match newlines # default behavior) ^ # anchor start of line e # \r?\n # if want preserve last crlf replace $ # ($ anchor end of line in multiline mode, in default # mode, $ means "end of string")
Comments
Post a Comment