0

can some one give me the Regular Expression that can check if a given string has any HTML code in it, and coming to think of it I would be bothered with <a href="something">something</a> exactly.

midhunhk
  • 5,560
  • 7
  • 52
  • 83
  • Possible duplicate of [How to validate that a string doesn't contain HTML using C#](http://stackoverflow.com/questions/204646/how-to-validate-that-a-string-doesnt-contain-html-using-c-sharp) – Naman Jul 13 '16 at 12:47

2 Answers2

2

Should be something like this

var pattern:RegExp = /<a\s.*?<\/a>/;
var index = str.search(pattern);
if (index != -1) // we have a match
Jonas Elfström
  • 30,834
  • 6
  • 70
  • 106
  • Note also that the following tool is invaluable when working with regex in flash: http://gskinner.com/RegExr/desktop/ + http://gskinner.com/RegExr/. –  May 31 '11 at 18:11
1

If you mean by "I would be bothered" that it is enough for you if the regex can detect anchor tags, then

if (/<a\s.*<\/a>/i.test(subject)) {
    // Successful match
}

should suffice. This return True if an anchor tag can be matched anywhere in the string.

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561