我如何检查一个字符串是否包含字符," "
但可以有多个字符,例如" "
等" "
?
我现在做的操作(仅适用于 的一个实例" "
)是:
if($(this).html() == " ")
我如何检查一个字符串是否包含字符," "
但可以有多个字符,例如" "
等" "
?
我现在做的操作(仅适用于 的一个实例" "
)是:
if($(this).html() == " ")
使用正则表达式:
/^(\ )+$/.test($(this).html());
^(?:[ ]* [ ]*)+$
JavaScript
if (/^(?:[ ]* [ ]*)+$/i.test(subject)) {
// Successful match
} else {
// Match attempt failed
}
描述
/^(?:[ ]* [ ]*)+$/
^ Start of string
(?:[ ]* [ ]*) Non-capturing Group 1 to infinite times [greedy]
Char class [ ] 0 to infinite times [greedy] matches:
The character
Literal
Char class [ ] 0 to infinite times [greedy] matches:
The character
$ End of string
使用简单的正则表达式
if(/^( )+$/.test($.trim($(this).text())))