Regex Word Boundary including hyphen

Viewed 83

With the regular expression \s{2}\b I'm trying to replace the last two whitespaces before a word with a pipe (|) using a Word Boundary, but it's ignoring the number -18.055,81. With what kind of expression I can also get the last two whitespaces before -18.055,81?

Example:

1234 - This is a test        18.055,81        -18.055,81        0,00        0,00        18.055,81

Results in:

1234 - This is a test       |18.055,81        -18.055,81       |0,00       |0,00       |18.055,81

What I want:

1234 - This is a test       |18.055,81       |-18.055,81       |0,00       |0,00       |18.055,81
1 Answers

You can use

\s{2}(?=-?\d)
\s{2}(?=-?\w)

See the regex demo. Details:

  • \s{2} - two whitespace chars
  • (?=-?\d) - that are immediately followed with an optional hyphen and then a digit.

If there are any other word chars expected (letters, or underscores), replace \d with \w.

Related