I want to replace one of the two consecutive numbers and erase it.

Asked 1 years ago, Updated 1 years ago, 55 views

I would like to do the following with the notepad editor.

0000129700001297
00001235    00001235
00001245    00001245

Numbers like the ones above

00001297
00001235
00001245

I'd like to have only one as shown in .
What are the alternatives?

regular-expression

2022-09-30 20:15

3 Answers

I would like to do the following with the notepad editor.

Notepad (notepad editor) does not contain regular expressions.Use another tool.


2022-09-30 20:15

Notepad++ allows you to use regular expressions (PCRE) for search and replacement, but you can also use PowerShell to handle this.

PowerShell script

Get-Content.\data.txt|
ForEach-Object {
  $arr = $_-split "\s+"
  If($arr[0]-eq$arr[1]){$arr[0]}Else{$_}
} |Out-File.\data_uniq.txt

data.txt

0000129700001297
00001235    00001235
00001245    00001245
00002000    00002001

data_uniq.txt

00001297
00001235
00001245
00002000    00002001


2022-09-30 20:15

Provide detailed and accurate information about your environment when you ask questions.

The answer may vary depending on the regular expression engine.
Windows standard Notepad.exe does not support regular expressions, but questions are tagged "regular expressions" from the beginning, so assume you are using a different editor for regular expressions.Also, assume it is a typical ECMA regular expression engine.

I think you can do it with capture and partial strings.

Before replacement: ^([0-9]+)\s+\1$
After replacement:\1


2022-09-30 20:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.