0

I have a three-part question about using Notepad++ to alter sets of numbers.

I have blocks of numbers as follows:

1415926535 8979323846 2643383279 5028841971 6939937510
5820974944 5923078164 0628620899 8628034825 3421170679

How can I change / alter this with Notepad++ as follows

  • break each line of 50 digits (5 sets of 10) into single lines with 25 digits per line
  • insert a hyphen after each 5 digits
  • ensure the line breaks to new line after 25 digits

As follows:

14159-26535-89793-23846-26433
83279-50288-41971-69399-37510
58209-74944-59230-78164-06286
20899-86280-34825-34211-70679

When this is done....

Is it possible to remove and replace specific characters with x's - as below:

14159-26535-xxxx3-xxxx6-xxxx3
83279-50288-xxxx1-xxxx9-xxxx0
58209-74944-xxxx0-xxxx4-xxxx6
20899-86280-xxxx5-xxxx1-xxxx9

Hopefully this is not too ambitious a request for Notepad++?

2
  • 2
    1) you should ask each question separately. 2) what have you tried so far? 3) where are you stuck? 4) please go read superuser.com/help/how-to-ask then 5) come back and edit your question(s). Commented Jul 3, 2023 at 20:24
  • You have identified what you want to happen but not what steps you have taken to accomplish these goals. Superuser does not create custom solutions but rather helps to overcome specific problems in the work you have done to achieve your solution. In this case, have you explored whether a macro might help to solve your problem (and if you have, perhaps you have a specific problem with the macro and need help on that). Additionally, have you explored the resources on notepad++ website to see what tools exist that may help you?
    – Brian
    Commented Jul 3, 2023 at 21:30

2 Answers 2

2

Can probably be one more efficiently... but this should also work.

Find what:

(.{5})(.{5}) .{4}(.).{4}(.) .{4}(.)(.{5}) (.{5}).{4}(.) .{4}(.).{4}(.)

Replace with:

$1-$2-xxxx$3-xxxx$4-xxxx$5\r\n$6-$7-xxxx$8-xxxx$9-xxxx$10

And Replace All.

enter image description here

1

How can I change / alter this with Notepad++ as follows

  • break each line of 50 digits (5 sets of 10) into single lines with 25 digits per line
  • insert a hyphen after each 5 digits ensure the line
  • breaks to new line after 25 digits

Using the manual for Notepad++, we can write expressions to search and replace the text as you require.

  1. To build a search expression, start with breaking down your starting text into subexpressions, which will allow you to construct your result. The expression should describe one line at a time, since each line has the same pattern. In this case, we want 1 line to become 2 lines. A line in the search expression contains the 50 digits in 5 equally sized groups and delimited by a space. To identify a digit, let's use a set of characters defined as:

[set] ⇒ This indicates a set of characters, for example, [abc] means any of the literal characters a, b or c. You can also use ranges by doing a hyphen between characters, for example [a-z] for any character from a to z

In our case, we want to match any character between 0-9, so we can use [0-9]. Next, we need to identify the groups in the subexpression, which can be done using Multiplying operators and {N}.

{ℕ} ⇒ Matches ℕ copies of the element it applies to (where ℕ is any decimal number).

N is determined from the replacement line pattern, which has 25 digits, grouped into 5 equally sized groups delimited by a '-'. The size of the group is N, which equals 5. Therefore, we can generate the replacement text searching for subexpressions [0-9]{5} in the original text.

Next, Numbered Capture Groups can be used to number the subexpression for the replace operation.

(subset) ⇒ Numbered Capture Group: Parentheses mark a subset of the regular expression, also known as a subset expression or capture group. The string matched by the contents of the parentheses (indicated by subset in this example) can be re-used with a backreference or as part of a replace operation

So, to match a single subexpression and have a numbered reference for later, we use ([0-9]{5}).

Then, the search expression to match a single line becomes:

([0-9]{5})([0-9]{5}) ([0-9]{5})([0-9]{5}) ([0-9]{5})([0-9]{5}) ([0-9]{5})([0-9]{5}) ([0-9]{5})([0-9]{5})
  1. In order to build the replace expression, a Substitution Escape Sequence, $N, can be used:

$ℕ, ${ℕ}, \ℕ ⇒ Returns what matched the ℕth subexpression (numbered capture group), where ℕ is a positive integer (1 or larger).

So, from the search expression above, $1 corresponds to 14159 (in the first line).

Putting it together, the replace expression for a single line would be:

$1-$2-$3-$4-$5\r\n$6-$7-$8-$9-$10

Is it possible to remove and replace specific characters with x's - as below:

Yes, this can be accomplished by choosing these characters in the appropriate subexpressions and selecting the correct numbered reference. For example, the search expression above contains ([0-9]{5}), which is a distinct numbered reference used later made up of 5 digits. If we wanted to replace the first character with 'x', this would become [0-9]([0-9]{4}). The corresponding portion of the replacement expression would be x$1 (assuming it is the first numbered reference). Similarly, If we wanted to replace the first 2 characters with 'x' [0-9]{2}([0-9]{3}). and xx$1 can be used, and so on.

For this specific case:

14159-26535-xxxx3-xxxx6-xxxx3

83279-50288-xxxx1-xxxx9-xxxx0

58209-74944-xxxx0-xxxx4-xxxx6

20899-86280-xxxx5-xxxx1-xxxx9

The search expression is:

([0-9]{5})([0-9]{5}) [0-9]{4}([0-9])[0-9]{4}([0-9]) [0-9]{4}([0-9])([0-9]{5}) ([0-9]{5})[0-9]{4}([0-9]) [0-9]{4}([0-9])[0-9]{4}([0-9])

The replace expression is:

$1-$2-xxxx$3-xxxx$4-xxxx$5\r\n$6-$7-xxxx$8-xxxx$9-xxxx$10

Not the answer you're looking for? Browse other questions tagged .