c# - .Net regex does not match/replcae pattern in multiline snippet -
i have following line:
var snippet = @"lane\rhemel hempstead\rhp39pp\r\rphone\r+44772930000\remail\ramberlie_10371599_wright@yahoo.co.uk\r\r\rlookin"
i replace phone number number of dots doing following:
snippet = regex.replace(snippet, @"^[^\s](\(?\+?[0-9]+\)?)?[0-9_ \-\(\)]+$", "....", regexoptions.ignorecase);
however nothing gets replaced, thought maybe not performing global search apparently .net regex global default.
any ideas?
can provide more information constraints? if want replace number on own line or without plus sign start, , newlines \r only, can use:
var regexstring = @"\+?[0-9]+\\r"; var targetstring = @"lane\rfoo bar\rhp39pp\r\rphone\r+44772930000\remail\ranon_10371599_name@example.com\r\r\rlookin"; var result = regex.replace(targetstring, regexstring, "....\\r");
result:
lane\rfoo bar\rhp39pp\r\rphone\r....\remail\ranon_10371599_name@example.com\r\r\rlookin
this not general, fits data provided. clarity, simple matching follows:
\+? - escape + sign, , make optional [0-9]+ - 1 or more digits \\r - escape backslash match end of line characters '\r'
Comments
Post a Comment