Sublime Forum

Removing mask of numeric string (or replace keeping digits)

#1

Hi,
I’ve searched for a method to remove all non-digit chars from a selection.
I didn’t found a proper package.
I tried CTRL + H with the RegEx /[^0-9]+/ but it replaced literally. The RegEx was not interpreted. Example:
I have this selection

bbsc 22.999.333/1111-77

, used CTRL + H this way:
image

and the replace result was:

/[^0-9]+/

What am I missing? Thanks!

0 Likes

#2

I believe the Find should be [^0-9] and Replace should be nothing (empty) and then a Replace All operation will simply remove any non digit characters.

1 Like

#3

It worked fine!
Let´s say that my selection have multiple lines. In this case de command is removing de linebreaks too and joining all. Can we preserve the line breaks too? Thanks!

0 Likes

#4

Yes, you just need to be more specific with the regex. Instead of [^0-9], it should be [^0-9\n] which excludes all numbers and new lines as well.

1 Like