java - Checking for matching tags -
so have question can't seem find answer have line of text contains not letters angle brackets
"<x>hello, welcome!</x>"
now how read line of text , check characters , check see if can find closing set match , if didn't display error message if did display correct message.
any or hints on awesome!
thanks!
re = /<(\w+)>.*<\/(\w+)>/i; function check(str) { match = str.match(re); if (match && match[1] == match[2]) return true; return false; } str1 = "<x>hello, welcome!</x>"; console.log(str1,check(str1)); str2 = "<x>hello, welcome!</x>"; console.log(str2,check(str2)); str3 = "<x>hello, welcome!</y>"; console.log(str3,check(str3));
i know actual parser better this, figured regular expressions still worth shot.
Comments
Post a Comment