user929404
user929404

Reputation: 2243

Regular expression to extract numbers before "."

I want to extract the number from a file name.

For example, from "i2mage001.png", I want to extract "i2mage" and "001".

I do not know if it will always be the last three numbers which I want to extract. It will be sufficient if I can just extract the numbers, although a regular expression to extract the "i2mage" would also be helpful

Upvotes: 0

Views: 166

Answers (2)

Bohemian
Bohemian

Reputation: 424983

This regex matches the digits part (without groups - ie the entire match is your target):

\d+(?=\.)

See live demo.


And this matches the part before that (ie i2image in your example):

.*\D(?=\d+\.)

See live demo.

Upvotes: 2

Stephan
Stephan

Reputation: 43013

Try this regex:

(.+?)(\d+)\.png

Description

Regular expression visualization

Demo

http://regex101.com/r/aI5tB2

Upvotes: 2

Related Questions