( \s* [\W_]* ) # (1), Not letters/numbers,
( [^\W_] ) # (2), Followed by letter/number
( # (3 start)
(?: # -----------
\w # Letter/number or _
| # or,
[[:punct:]_-] # Punctuation
(?= [\w[:punct:]-] ) # if followed by punctuation/letter/number or '-'
| #or,
[?.!] # (Add) Special word ending punctuation
)* # ----------- 0 to many times
) # (3 end)
var str = 'This "is the ,input _str,ng, the End ';
console.log(str);
console.log(str.replace(/(\s*[\W_]*)([^\W_])((?:\w|[[:punct:]_-](?=[\w[:punct:]-])|[?.!])*)/g, function( match, p1,p2,p3) {return p1 + p2.toUpperCase() + p3;}));
1 回答
在语言中间找到真正的单词中断可能会更多一些
比使用正则表达式边界更复杂 .