我有一些类名,我这样得到它们:
var classname = $(this).attr("class");
这是其中的两个示例:
fa fa-bold
fa fa-bell-o separator
现在我需要这些结果:
bold
bell-o
<小时/>
线索是: fa-
之后和 之前的所有内容。我怎样才能做到这一点?
最佳答案
The clue is: everything after
fa-
and before. How can I do that?
您可以捕获 fa-
之后的所有非空格字符:
/fa-(\S+)/
然后使用.match()
方法:
var match = 'fa fa-bell-o separator'.match(/fa-(\S+)/);
var result = match ? match[1] : null;
// "bell-o"
关于javascript - 如何选择两个特定字符之间的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34845671/