[英]How to remove text between numbers in notepad++
I have texts like我有类似的文字
3.6. Sam
3.7. Willy
4.1. drake
4.2. nadeem
I need output like我需要像这样的输出
3-6 Sam
3-7 Willy
4-1 drake
4-2 nadeem
I tried replace \\d{1}.\\d{1}.
我尝试替换
\\d{1}.\\d{1}.
with \\d{1}-\\d{1}
& later with $1-$2
使用
\\d{1}-\\d{1}
和更高版本的$1-$2
But I cant retain the number.但我不能保留号码。 Can anyone help me with this
谁能帮我这个
Use the following Regex:使用以下正则表达式:
(\d)\.(\d)\.
And replace with:并替换为:
$1-$2
You were going wrong because you need capture groups around the numbers.你错了,因为你需要围绕数字捕获组。
(\\d)
instead of just \\d
. (\\d)
而不仅仅是\\d
。
And you don't need to specify {1}
if it's just one, you can leave that out.如果它只是一个,则不需要指定
{1}
,您可以将其省略。 Also you put .
你也把
.
but that represents any character, not just the period/fullstop, for that you have to escape it with a slash as \\.
但这代表任何字符,而不仅仅是句点/句号,因为你必须用斜杠将它转义为
\\.
. .
^(\\d+)\\.(\\d+)\\.
^(\\d+)\\.(\\d+)\\.
$1-$2
$1-$2
. matches newline
. matches newline
. matches newline
Explanation:解释:
^ # beginning of line
(\d+) # group 1, 1 or more digits
\. # a dot
(\d+) # group 2, 1 or more digits
\. # a dot
Screen capture (before):屏幕截图(之前):
Screen capture (after):屏幕截图(之后):
Another option is to make use of \\K
and use a single group in the replacement.另一种选择是使用
\\K
并在替换中使用单个组。
Find what:找什么:
\d\K\.(\d)\.
Replace with:用。。。来代替:
-$1
Explanation解释
\\d
Match a single digit (use \\d+
to match 1 or more digits) \\d
匹配单个数字(使用\\d+
匹配 1 个或多个数字)\\K
Reset starting point of the reported match (forget what was matched) \\K
重置报告匹配的起点(忘记匹配的内容)\\.(\\d)\\.
Capture a digit in group 1 between matching a dot on the left and rightIf all your matches are at the start of the string, you prepend a ^
to the pattern.如果所有匹配项都在字符串的开头,则在模式前添加
^
。
A shortest forum of regex will look like this...一个最短的正则表达式论坛看起来像这样......
Find what: \\.(\\d)\\.
找到什么:
\\.(\\d)\\.
Replace with: -$1
or ↝ -\\1
替换为:
-$1
或 ↝ -\\1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.