我有一个字符串列表,从许多cssRule指定规则的selectorText采取琴弦具有一般形式(关于正则表达式不知道):基于特定条件从字符串中提取子字符串的有效方法?
".selector1 .elementClass[, ]*"
具体的例子如下:
".point"
".point.lackofclearance .stand_b, .point.lackofclearance .stand_c"
".point .path_a,.point .path,.point .stand"
".blink_on .point.direction_open .stand"
".blink_off .point.a_in_ratc_selection .path_a, .blink_off .point
.path.a_in_ratc_selection"
现在,在这些字符串中,有趣的是包含字符串“point
”的字符串,并且在包含字符串“point
”的字符串中,我感兴趣的是紧接在“.point.
”之后并且在下一个空格字符。它们代表我希望阅读的元素状态。
例如:
从“.point
”没有这样子提取,并从“.point .path_a,.point .path,.point .stand
”也没什么提取,因为“.point.
”不存在作为一件都没有。 BUT“.point.lackofclearance .stand_b, .point.lackofclearance .stand_c
”我想提取“lackofclearance
”,当然是第一次和第二次出现。
我在我的脑袋已经是一个理念,那就是:
- 检查字符串“
point
”的存在 - 如果是,“
,
” - 对于每个结果分割字符串串,由 '
'(空格字符)
- 对于每个得到的子串,含有分裂 “
.point
”。,由 '.
'(点炭)拆分 - 带上一个分裂的第二子
是否有身体有另一种意见认为,这样做的一个别致的方式,可能会更短,或更有效,或两者... 它已经在做JavaScript中,在Chrome中,jQuery可用。
很抱歉,您提供的正则表达式,只返回第一次出现,所以如果我有“.point.lackofclearance .stand_b,.point.lackofclearanceCritical .stand_c”,我只能提取lackofclearance,但我也想lackofclearanceCritical 。然后我尝试了这个/\.point\.(\S+)/g RegEx,我得到的结果是[“.point.lackofclearance”,“.point.lackofclearanceCritical”],并不是我想要的,但是我可以应用各自的RegEx,并采取我想要的 – StaticBug