[英]Regular Expression matches similar strings
I am trying to alter classnames for a module via jquery and right now I have this RegEx 我正在尝试通过jquery更改模块的类名,现在我有此RegEx
/module-\\w+/gi / module- \\ w + / gi
Used in this fashion 以这种方式使用
//// Removes all module-xxxx classes
var classes = $target[0].className.replace(/module-\w+/gi, '');
This has worked fine until now however I have to alter the structure of my module class so that it resembles this 到现在为止,这一直很好,但是我必须更改模块类的结构,使其类似于
<div class="module">
<div class="module-header">
<div class="module-header-content module-blue ..."></div>
</div>
<div class="module-content"></div>
</div>
The ... just means there could be other class names. ...只是意味着可能还有其他的类名。
I need to change the RegEx so that it matches only module-blue (could be module-default, module-green, module-whatever, but always in the format of module-COLORNAME ) and not doesn't match module-header-content as well. 我需要更改RegEx,以使其仅匹配模块蓝色 (可以是模块默认,模块绿色,任何模块,但始终以module-COLORNAME的格式),而不匹配module-header-content也一样
The jquery selects the classname of: module-header-content module-blue jQuery选择以下类名:module-header-content module-blue
var classes = $target[0].className.replace(/\bmodule-\w+(?!-)\b/gi, '');
With word boundaries, the expression has to match an entire group of module-
followed by at least one letter that is not followed by a dash. 与字边界,表达式必须匹配的整个组module-
随后在至少一个字母后面没有用破折号。
http://jsfiddle.net/ExplosionPIlls/WqbKJ/ http://jsfiddle.net/ExplosionPIlls/WqbKJ/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.