RaceBase
RaceBase

Reputation: 18868

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. :)

Upvotes: 1

Views: 4055

Answers (2)

hwnd
hwnd

Reputation: 70750

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

Upvotes: 2

Kassym Dorsel
Kassym Dorsel

Reputation: 4843

Open the Find Replace in Sublime. You'll search for:

[^\d\n]+

and replace with an empty string.

The Regex matches everything except numbers or newlines

Upvotes: 3

Related Questions