我想像这样替换所有文本:
"latitude": "32.336533",
Run Code Online (Sandbox Code Playgroud)
有了这个:
"latitude": 32.336533,
Run Code Online (Sandbox Code Playgroud)
我正在使用记事本++。
小智 7
使用 Regex 使用以下模式:
"([0-9]+\.{0,1}[0-9]*)"
Run Code Online (Sandbox Code Playgroud)
并替换为:
\1
Run Code Online (Sandbox Code Playgroud)
这对我来说有replace all记事本++的功能。它也会找到"12."并删除双引号。要进行更全面的搜索,请使用此正则表达式模式:
"(\-{0,1}[0-9]+(\.[0-9]+){0,1})"
Run Code Online (Sandbox Code Playgroud)
它实际上也会找到负数,并且只匹配小数点后的数字的浮点数。
解释:
它会匹配
" ; a leading double quote
( ; followed by the outer subpattern (in backreference \1:
\-{0,1} ; an optional minus sign
[0-9]+ ; followed by 1 or more decimal digits (could be replaced by \d)
( ; followed by the next subpattern
\. ; a decimal point
[0-9]+ ; followed by 1 or more digits
){0,1} ; maximal 1 occurrence of this subpattern, and it's optional
) ; end of the outer subpattern
" ; followed by the trailing double quote
Run Code Online (Sandbox Code Playgroud)
反向引用\1包括外部子模式中的所有内容,包括内部子模式(如果存在)。您可以\d用于[0-9]课程并使用问号?而不是最后一{0,1}组。请记住,使用?可能会改变模式的贪婪性。
例子:
记事本++中的文本带有以下几行
"latitude": "-32.336533",
"latitude": "32.336533",
"foo": "14"
"bla": "12."
"to7": "12.a"
Run Code Online (Sandbox Code Playgroud)
将在应用“全部替换”后更改
"latitude": -32.336533,
"latitude": 32.336533,
"foo": 14
"bla": "12."
"to7": "12.a"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9481 次 |
| 最近记录: |