Click here to Skip to main content
15,564,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I want to write regx search pattern. Here I have written one which is working fine but again I need some modifications.

Dim SearchPattern As String = "<a.+?a>"


If I match this string
"this is <a href='www.hindustanexperts.com'><img src = 'google.com/images'/></a><span>trial</span><a href='googl.com'>sample2</a> an example."


will return me

<a href='www.hindustanexperts.com'><img src = 'google.com/images'/></a>

and

<a href='googl.com'>sample2</a>


What I need is i dont want to include nested tags i.e
<a href='www.hindustanexperts.com'><img src = 'google.com/images'/></a>


I just want only
<a href='googl.com'>sample2</a>


Any help pls.....

Thanks in advance
Posted

1 solution

Hi hiren
Try this expression
^<a.+>[a-z A-Z 0-9]+</a>$
It works for me with your provided sample.
Hope this is will help.


Thanks,
Mark it as Answer if you find it Correct.
 
Share this answer
 
Comments
hiren soni 18-Nov-10 13:25pm    
Hi Iqbal,

Can you please check it for one more time because it didnt work for me.
And please check for other html tag also rather than my given example.

Thanks a lot for your interest
Shahriar Iqbal Chowdhury/Galib 18-Nov-10 15:28pm    
hi hiren,

this expression works for me and it can handle any nested html tags. Idea is
it will only validate true if contains text/numbers inside <a> tag, any other nested tag/special character will be detracted as invalid. I guess you should check the way you are validating.If you are using Regex
Try this code
Regex regE = new Regex("<a.+>[a-z A-Z 0-9]+</a>");
This will surely work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900