c# - Regex.replace will not replace multiline text rows with beginning chars to html block -


ich have problem regex replacing function in c# explicit in multiline text. in text have different rows special chars (eg: & , &&) in beginning rows have convert in e.g. html. similar markdown conversion...

an example text following:

this normal demo text. &here other demo text. , 1 more demo text. &&here continue text. bla bla blaaa... 

the text should after replacing following text beginning , end html tag:

this normal demo text. <b>here other demo text.</b> , 1 more demo text. <em>here continue text...</em> bla bla blaaa... 

for replacing & , && have created following c# code:

private string startconvert(str text)  { text = regex.replace(text, "^[&]{1}((?![&]).+)$", "<b>$1</b>", regexoptions.multiline); text = regex.replace(text, "^[&]{2}((?![&]).+)$", "<em>$1</em>", regexoptions.multiline); } 

after running wrong followings:

this normal demo text. </b>ere other demo text. , 1 more demo text. </em>ere continue text... bla bla blaaa... 

why not work correctly , why closed tags in front of rows. if single line works correctly not in multiline.

thanks help

i assume file windows eof encoded: \r\n.

the expression: "^[&]{1}((?![&]).+)$" match &here other demo text.\r\n.

the reference ((?![&]).+) here other demo text.\r.

having replacing string: <b>here other demo text.\r</b>

<b>here other demo text.\r ^___________________________| 

cr \r returns cursor beginning of line.

</b>ere other demo text.\r |__^ 

rewriting <b>h </b>


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -