DanielAttard
DanielAttard

Reputation: 3615

Regex expression to exclude spaces and return numbers only

At the risk of being downvoted again, I need to ask another fairly basic regex question. I am trying to extract the number 8976 from the following string:

1 / 8976             RT110539

The number that I am trying to grab in this example is 4-digits long, but sometimes it could be only 1-digit or as many as 6-digits. This is the regex that I have created so far:

[/](.){6}

This works, but only partially because it is returning the forward slash and spaces / 8976 , but I only want to grab the number itself. How should I modify this regex to return the number only, following the forward slash? Thanks.

Upvotes: 0

Views: 764

Answers (1)

Pruthvi Raj
Pruthvi Raj

Reputation: 3036

Try this:

(?<=\/)\s*(\d{1,6})

DEMO

Upvotes: 1

Related Questions