我想写一个JavaScript正则表达式,它匹配点后面的所有第一个字母,一个或多个空格(换行符),如果这个字母是小写的。我强调了我想要匹配的字母。
图片中的文字:
RegExr v3 was created by gskinner.com, and is proudly hosted by Media Temple.
Edit the Expression & Text to see matches. roll over matches or the expression for details. PCRE & Javascript flavors of RegEx are supported.
The side bar includes a Cheatsheet, full Reference, and Help. You can also Save & Share with the Community, and view patterns you create or favorite in My Patterns.
explore results with the Tools below. Replace & List output custom results. Details lists capture groups.explain describes your expression in plain English.
答案 0 :(得分:1)
你需要这样的东西:
var str = document.getElementById('text').innerHTML;
console.log(str.match(/[.]\s+[a-z]/g));
/*
EDIT - If you want to get only the letters
*/
var matches = [];
var regex = /[.]\s+([a-z])/g;
while (res = regex.exec(str)) {
matches.push(res[1]);
}
console.log(matches);
#text {
width: 100%;
}
<textarea id="text" rows="10">
RegExr v3 was created by gskinner.com, and is proudly hosted by Media Temple.
Edit the Expression & Text to see matches. roll over matches or the expression for details. PCRE & Javascript flavors of RegEx are supported.
The side bar includes a Cheatsheet, full Reference, and Help. You can also Save & Share with the Community, and view patterns you create or favorite in My Patterns.
explore results with the Tools below. Replace & List output custom results. Details lists capture groups.explain describes your expression in plain English.
</textarea>
/[.]\s+[a-z]/g
[.]
- 匹配点字符\s
- 匹配单个空格字符,包括空格,制表符,换页符,换行符。相当于[\ f \ n \ r \ t \ v \ u00a0 \ u1680 \ u180e \ u2000- \ u200a \ u2028 \ u2029 \ u202f \ u205f \ u3000 \ ufeff] +
- 将前面的表达式匹配1次或更多次。相当于{1,} [a-z]
- 匹配a
到z
g
- 全球搜索答案 1 :(得分:0)
我认为这样做:
/\.\s+([a-z]{1})/g
\.
匹配一个点
\s+
匹配1个或更多空格
([a-z]{1})
捕获第一个小写字母。
g
全球研究
你可以在这句话中试试:https://regex101.com/r/d6JXSR/1