This regex should work:
String str = @"<a href="":$451$142"">some thing</a> "+
@" <a href="":$14$15"">some thing</a> "+
@" <a href="":$3$16"">some thing</a> "+
@" <a href="":$312$17"">some thing</a> ";
String newStr = Regex.Replace(str,@":\$\d+\$\d+", "#");
System.Console.WriteLine(str);
System.Console.WriteLine("\n\n" + newStr);
It yields:
<a href=":$451$142">some thing</a> <a href=":$14$15">some thing</a> <a href
=":$3$16">some thing</a> <a href=":$312$17">some thing</a>
<a href="#">some thing</a> <a href="#">some thing</a> <a href="#">some thin
g</a> <a href="#">some thing</a>
The regular expression: :\$\d+\$\d+
will match any piece of text starting with a :
, followed by a $
(the $
is a special character in regular expression language and thus needs to be escaped with an extra \
in front). The $
will in turn need to be followed by one or more digits (\d+
) which in turn is followed by another :
which is followed by one or more numbers (\d+
). Please check this tutorial for more information.
Although in this case regular expressions did help, it is highly recommended that you do not use them to parse languages. Please use a dedicated framework such as HTML Agility Pack to do any HTML related processes. Take a look here for an example similar to what you seem to be trying to do.