I am writing as SQL query which might return HTML text also. HTML Tags are fine for me, because I want to show it formatted with the HTML tags in the front end. But I do not need links. I mean is there anyway I can strip off the hyper links only from the column. just the anchor tag. I am so bad in Regular Expressions, though i think that might be the solution for this. Any help!
1 Answer
This should work fine for links:
<a[^>]*>(.*?)<\/a>
Since you say you don't understand regular expressions, I might as well explain. The <a part is straightforward, the [^>]* will match anything up to the closing bracket, the bracket is just the bracket. (.*?) matches anything, regardless of length, empty links as well. The ? is required so that it becomes non-greedy, so it stops at the first closing tag. <\/a> matches the closing tag.
Edit: if you have spaces in between your tags, you can use <a[^>]*>((?:.|\s)*?)<\/a>. Notice I added the (?:.|\s)*? in place of .*?. The .|\s means match any character or space, the ?: indicate a non capturing group, since we don't care which particular character was matched.