[英]How to remove dot followed by non digit or any special character?
Example: ABCD, NC exg. 58/2095, s.2.7 A. 2A.
示例: ABCD, NC exg. 58/2095, s.2.7 A. 2A.
ABCD, NC exg. 58/2095, s.2.7 A. 2A.
is the text and am using Regexp是文本,正在使用 Regexp
`String.replace(/([az]+).|.([ ?!\\d])/ig, '$1') `String.replace(/([az]+).|.([ ?!\\d])/ig, '$1')
O/p : Missing some Text from the Text. O/p : 文本中缺少一些文本。
Expected is:
ABCD, NC exg 58/2095, s.2.7 A2A
预期为:ABCD, NC exg 58/2095, s.2.7 A2A
--dot followed by non digit(special Char or Alphabets) should replace with null. --dot 后跟非数字(特殊字符或字母)应替换为 null。
You can use alternation and grouping.您可以使用交替和分组。
([az]+)\\.
- Matches one or more character (captures as group) followed by dot. - 匹配一个或多个字符(捕获为一组)后跟点。
\\.([az]+)
- Matches dot followed by one or more character (captures chracters as group) \\.([az]+)
- 匹配后跟一个或多个字符的点(将字符捕获为一组)
And in replace by the matched group.并由匹配的组替换。
let str = `ABCD, NC exg. 58/2095, s. 2.7 ` let op = str.replace(/([az]+)\\.|\\.([az]+)/ig, '$1') console.log(op)
If your input is only ASCII, just replace every letter followed by a dot with the character itself:如果您的输入只是 ASCII,只需将每个字母后跟一个点替换为字符本身:
console.log( "ABCD, NC exg. 58/2095, s. 2.7".replace(/([az])\\./ig, '$1') );
Removing every special character.删除每个特殊字符。
Because that's what you are telling it to do.因为这就是你要它做的事情。 [^\\w.\\s]
matches every character that is not a letter, number, _
, .
[^\\w.\\s]
匹配每个不是字母、数字、 _
、 的字符.
or white space.或空白。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.