简体   繁体   English

如何在记事本++中删除数字之间的文本

[英]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 \\.但这代表任何字符,而不仅仅是句点/句号,因为你必须用斜杠将它转义为\\. . .

  • Ctrl + H Ctrl + H
  • Find what: ^(\\d+)\\.(\\d+)\\.找出什么: ^(\\d+)\\.(\\d+)\\.
  • Replace with: $1-$2替换为: $1-$2
  • CHECK Wrap around检查环绕
  • CHECK Regular expression检查正则表达式
  • UNCHECK . matches newline取消选中. matches newline . matches newline
  • Replace all全部替换

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 right在匹配左侧和右侧的一个点之间捕获组 1 中的一个数字

Regex demo正则表达式演示

If 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM