.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

RegEx to get links attributes in order to replace

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :WPF

I have anchor tags which are unusually formatted.

I firstly I have tags which are as below <a name="1">text</a>

I need to get the value from the name attribute.

I then need to get the whole 1st part of the tag <a name="1"> so I can replace it with a properly formated tag i.e. <a href="URL" name="1">

I am a little lost in the world of Reg Ex and all the examples presume that there is a "href" followed by a formatted URL present.


As you can see I have to c# code to replace the regex output but just dont know where to start with the pattern.

public String replaceID_withLinksrcs(String Text, IRepository<Corp.Web.Model.Link> objLinks)
String parsedtext;
parsedtext = Text.Replace("shape=\"rect\"","");
String t18 = @parsedtext;
String p18 = @"/<^a name= $>";
t18 = Regex.Replace(t18, p18, new MatchEvaluator(delegate(Match match) { return MyLinkURLS(match, objLinks); }));
return t18;


View Complete Post

More Related Resource Links

Regex.replace [h2] to


I try to replace [h2] to <h2>
I use this coding:

string o = "<h2>test</h2>";
o = Regex.Replace(o, "[h2]", "<h2>");
o = Regex.Replace(o, "[/h2]", "</h2>");


But the result after the first regex is:


So that is not what i want.
After the first 1, he should make:


Whats wrong?

regex replace - but with a few exceptions.


I have a string containing HTML and I need to replace some words to be links (I know, working with regex against HTML is not accepted by all developers, but I cannot see an easy solution with any other technique) - I do this with the following code;

string lNewHTML = Regex.Replace(lOldHTML, "(\bword1\b|\bword2|word3\b)", "<a href=\"page.aspx#$1\">$1</a>", RegexOptions.IgnoreCase);

The code works, but I need to include some exceptions to the replace - e.g. I will not replace anything i an img-, li- and a-tag (including link-text and attributes like href and title) but still allow replacements in p-, td- and div-tags.

By using the following code I can avoid replacing in attributes;


But with the above code it still replaces words in e.g. links and headlines which is a no-go.

The last example I have seems to do what I need - but if my HTML-string contains more than a few characters my application crashes;


Can anyone figure out a solution to this?

Replace space from string - REGEX.



I have some problem with RegEx.

I have text:

"something here [tagQuote=Name of Author]bla bla bla[/tagQuote] something here"

And now I want to replace all the whitespace character in quote attribute with "%#%#%#%".

So I want to have: [tagQuote=Name%#%#%#%of%#%#%#%Author]bla bla bla[/tagQuote]

So remove all of the whitespaces between "[tagQuote=" and "]...[/tagQuote]"

XML Replace all attributes of value X with value Y

Hi guys, Im trying to replace data in an xml column as some sku's for a product have been discontinued and where customers have saved them to the database they want to replace them with similar products at the customers request

WHILE EXISTS (SELECT * FROM [ProductDetails] WHERE [SegmentXml].exist('/ProductItem[@ProductCode = "SKU13_23"]') = 1)

UPDATE [ProductDetails]

SET [SegmentXml].modify('replace value of (/ProductItem[@ProductCode = "SKU13_23"]/text())[1] with "SKU11_23"')


Need Regex.Replace help for lowercase to uppercase



I need help with Regex replacement.  I searched the web and tried for several hours but I just can't get it working. 

In theory, what I need to do is simple: make sure all element names in HTML tags are uppercase, e.g.:




If anyone could help me out I would greatly appreciate it!  


Using Regex.Replace



I am reading in a file and performing a search & replace for specific matches. 

Is it possible to do the following with regular expressions? NOTE: the comma and slash being inserted in the output.

strLine = Regex.Replace(strLine, "<?data [REGEX HERE]?>", "<?data,\...\?>");

Input:  <?data ...?>

Output: <?data,\...\?>


how to use regex to identify the number of links in html source code


Hi, all, how to count the number of links in a piece of html source code, is it possible to use regex, for example, create a regex "href" and to count for matches? thanks in advance.

for example, a segment of html code like this:

<TD style="PADDING-RIGHT: 3px" width=150><A id=a588660 onclick="return Evar16_tracking('588660');" href="/products/shprodde.asp?sku=588940"><IMG style="BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc

RegEx.Replace - why is capture group 1 empty?


Using PowerShell to illustrate:

$t = '<img src="r1.jpg" width="330" class="image">'
$pattern = 'src[\s]*?=[\s]*?[''|"](.+?jpg)[''|"][\s]*?width=[''|"]330[''|"]'

[RegEx]::Match($t, $pattern)


Groups   : {src="r1.jpg" width="330", r1.jpg}
Success  : True
Captures : {src="r1.jpg" width="330"}
Index    : 5
Length   : 24
Value    : src="r1.jpg" width="330"

Just to confirm,


gives: r1.jpg



problem with using regex removing html tag attributes


hi,all, I have the following code:

wstring myapp::PreProcessingTagStr(wstring wstrHtmlSrc)
	const wregex wregPattern(L"\\s*<([a-z][a-z0-9]*)[^>]*?(/?)>.*?</([a-z][a-z0-9]*)>\\s*");
	const wstring replacer = L"<$1$2>T";
	return regex_replace(wstrHtmlSrc, wregPattern, replacer);

void myapp::OnBnClickedTestButton5()
	// TODO: Add your control notification handler code here

	wstring wstrTxt = L"<SPAN class=scndInfo>(Hayes., UK, United Kingdom)</SPAN>";
	m_strVIPSResult += CString(L"") + PreProcessingTagStr(wstrTxt).c_str();

and it supposes to generate something like:


but the regex matches nothing, it just gives out the original string "

Xml Links

Xml Links:-
1)Fill data in GridView using XML:-

2)Binding to XML Data in ASP.NET 2.0:-

3)Binding xml data to gridview Template field:-

4)Binding xml to dropdownlist:-

5)Programming XML with C# & Connecting Data and XML via ADO .NET

6)DataSet.ReadXmlSchema() Method

7)Using XML with DataSets:-

8)ow To Read XML Data into a DataSet by Using Visual C# .NET

9)MSDN(XML imp links)

10)Xml Classes

11)Image to XML file for file transfer using ASP.NET and C#

I need help with imagebutton links


I have imagebuttons as links and i added the attributes for mousedown, up and out. That works fine.  I cant seem to figure out how that the imagebutton itself, when pushed, stays down and returns to normal when the user clicks another link....

what I was thinking of doing is calling a method on the onclick event of the button and letting it check whether there is another button pushed down then to send the found link button to its orginal state.

I figured doing the call and checking of the buttons would be long winded with the method, so there must be an easier way to do this ?






Is it possible with SQL sorted in descending order according to the word?
In Table I shrajeno Mastercard, Visa, Diners etc ...

All Visa are the first in the order, another Mastercard, etc. ...

Something does not work: ORDER BY PaymentType = 'Visa';

I would not want to work in one field PaymentId (111,222,33, etc. ..) and then use the ORDER BY.

Is this possible in such a way?

Linq qry with order by basic questions


I have never tried a group by with linq, now I do and I'm stuck.

I try to convert this sql statement to its linq counterpart :

SELECT COUNT(tb_Mailer_Smses.Id) AS [cnt], tb_Mailer_mailing.Id As [Id]
,SUM( CASE WHEN tb_Mailer_smses.DLRStatus = 200 THEN 1 ELSE 0 END) As [Delivered]
FROM tb_Mailer_mailing INNER JOIN
tb_Mailer_Smses ON tb_Mailer_mailing.Id = tb_Mailer_Smses.MailingId
WHERE tb_Mailer_mailing.ApplicationId = 1
GROUP BY tb_Mailer_mailing.Id

Is there some one who can me show me the convertion process ?

Can I replace the EntityObject as base-class in Entity Designer 3.5 sp1?


I'm using EF3.5sp1 for a project, and I've been working around many of its problems... as such, my entity partial classes have a lot of logic in them for change-tracking and whatnot.  Obviously, I'd like to factor this logic out into a common base class, but of course all my objects must derive from EntityObject.  Is it possible to tell them to derive from some class of my own invention (which would actually likely derive from EntityObject themselves)?

I'd rather avoid editing the EDMX file unless the changes will be safe on entity-model-update, since I'm still making changes to the database schema in this early state of my project.


Also, is there any good workaround for the fact that the change isn't tracked when you change EntityReference.EntityKey?

Regex pattern for validating IPv6


Can anyone can make a regular expression pattern for validating IPv6 (not IPv4)?

Ipv6 has many formats and aliases. I tried making the pattern but written in a lot of codes (i'm not sure my code below will be 100% accepting valid formats and 100% declines invalid formats).


Custom Attributes + Reflection


I recently started messing around with custom attributes and reflection. In my code below GetCustomAttributes never return a list (it should return atleast one):

Am i defining the custom attrib wrong?

public class GOrder:IOrder
        public string CertProductIDString { get; set; }

        public string GetRESTParams()
            string data = string.Empty;
                System.Reflection.MemberInfo inf = this.GetType();
                object[] attributes;
                attributes =  inf.GetCustomAttributes(typeof(RESTParamAttrib), true);
                foreach (Object attribute in attributes)
                    RESTParamAttrib attrib = (RESTParamAttrib)attribute;
                    data = data + string.Format("\nData: {0}", attrib.Param);

            catch (Exception ex)

                throw ex;

            return data;

    public class RESTParamAttrib:System.Attribute
        public RESTParamAttrib (string param)
            Param = param;

        public string
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend