Question

I have SQL that is searching a column in a table that can contain a lengthy amount of text that represents HTML.

within that text, I want to look for specific links.

my like statement looks like: '%Controller/action/' + @ID + '%'

in this example I'm searching for the link Controller/action/12 but it will also pull back Controller/action/125

It's obviously the wildcard at the end that is causing this issue, but because these links can be anywhere in the HTML I need the wildcard. Since I'm looking at anchor tags hrefs I tried '%Controller/action/' + @ID + '"%', but the issue with this is there could be spaces at the end of the href. I can't seem to find SQL that will accomplish what I'm looking for.

Some examples of anchor tags that I'd be searching for.

<a class="Hyperlink" href="http://test.mydomain.com/Test/account/43 ">

<a class="Hyperlink" href="http://test.mydomain.com/Test/account/43">

Was it helpful?

Solution

With regular expressions it is a bit easier. You can match after the numbers to non numbers. For example something similar:

'Controller/action/' + @ID + '\D' 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top