jhon.smith
jhon.smith

Reputation: 2043

regex to extract the number from string

I have a string like this

file-myfle_20130207_094852am.csv

how do i go about writing the regex to extract only the numbers

20130207094852

Upvotes: 1

Views: 103

Answers (2)

David M
David M

Reputation: 4376

See my comment on the question for context.

From a shell:

echo file-myfle_20130207_094852am.csv | tr -cd /0-9/
20130207094852

With Perl:

echo file-myfle_20130207_094852am.csv | perl -pe 's/\D//g'
20130207094852

Upvotes: 0

Simon Whitehead
Simon Whitehead

Reputation: 65049

Like this (this is pretty common among Regex tutorials)

\d+

Each group will be the numbers.

Upvotes: 5

Related Questions