0

UltraEdit / Unix regular expressions. I want to replace all lines with a name + whitespace + number with a name + # + number

Example : SANTIAGO 80,00 will be replaced with SANTIAGO#80,00 and all the lines will proceed like that

I can find what I want searching in Unix expression : [^t^b][0-9]

1 Answers1

0

UltraEdit has three regular expression engines.

First solution using UltraEdit regular expression engine with a tagged regular expression:

Find what: ^([^t ]^)^([0-9]^)
Replace with: ^1#^2

Second solution using Unix or Perl regular expression engine doing the same as above also using marking groups and backreferences:

Find what: ([\t ])([0-9])
Replace with: \1#\2

These two solutions search for a horizontal tab character or a normal space followed by a digit, tag those two characters for back-referencing them in replace string which inserts # between them.

With the most powerful Perl regular expression it is also possible to just insert # between tab/space and a digit which results in less data recorded for undo.

Find what: (?<=[\t ])(?=\d)
Replace with: #

The Perl regular expression search string uses a positive lookbehind and a positive lookahead to find a position on where to insert #.

Also possible with Perl regular expression engine:

Find what: [\t ]\K(?=\d)
Replace with: #

This is the same as above, but with simply searching for a tab or space and resetting the start location of $0 to the position after the whitespace character instead of using a positive lookbehind before checking with positive lookahead if next character is a digit.

Mofi
  • 46,139
  • 17
  • 80
  • 143