user871695
user871695

Reputation: 431

Regular Expressions removing characters between digit numbers

By using a regular experssion.. how can i remove any characteres beween digit numbers

example:

119198421682C4 --> 1191984216824
11919AA23B3 --> 11919233

Thanks

Upvotes: 0

Views: 557

Answers (2)

Ben Taitelbaum
Ben Taitelbaum

Reputation: 7403

Using sed:

echo '119198421682C4' | sed -E 's/([0-9])[^0-9]+([0-9])/\1\2/g'
echo '11919AA23B3' | sed -E 's/([0-9])[^0-9]+([0-9])/\1\2/g'

Upvotes: 0

Paul
Paul

Reputation: 141839

If you want to just remove everything that isn't a number replace all matches of [^0-9] with the empty string. In Javascript (for example) that would look like:

'11919AA23B3'.replace(/[^\d]/g, '');

\d is just a short form for [0-9]. When I run that in Chrome's console I get: "11919233"

Upvotes: 1

Related Questions