在jquery中匹配模式后获得完整的单词

时间:2016-08-30 14:55:42

标签: javascript jquery regex

var myVar= $("[class*=TextType]").attr("class")

//myVar returns Textabc Textxyz TextTypeTestingText
//I want to get TextTypeTestingText from myVar

var FinalWord = myVar.match(/TextType+/g)

alert(FinalWord)

这只会提醒TextType,但不会提醒我正在寻找的整个单词

1 个答案:

答案 0 :(得分:0)

您只需要匹配字母,而不是重复最后一个字符(在您的情况下为e)。

'Textabc Textxyz TextTypeTestingText'.match(/TextType\w*/)[0]; // TextTypeTestingText

如果您还想匹配其他非空格字符,可以使用/TextType\S+/