Search code examples
regexreplacenumberssublimetext3except

Sublime Regex to replace everything other than numbers


I have sample data

| 1 |
| 2 |
| 3 |

I want to remove everything else except numbers, keeping line (\n) as usually.

Output:

1
2
3

I am bit new to Sublime and Regex. :)


Solution

  • Based on your sample data, you can use the following.

    Find: ^\D+|\D+$
    Replace:
    

    This matches the beginning of the string, followed by any character of non-digits (1 or more times) OR any character of non-digits (1 or more times) preceded by the end of the string.

    Live Demo