Rhonda
Rhonda

Reputation: 1721

Regex to isolate two digits in middle of string

I have couple of strings

Staten Island\31R722

Manhattan\03M185

Queens\24Q058

where I would like to isolate and output two digits after \

Output for

Staten Island\31R722 should be 31 Manhattan\03M185 should be 03 Queens\24Q058 should be 24

This is the regex I have so far

\w+\s*\w+\\

I'm not sure how to eliminate the single letter and three characters after it.

It is always a single letter and three characters.

Upvotes: 2

Views: 2334

Answers (2)

vks
vks

Reputation: 67968

^\w+(?:\s+\w+)?\\|[A-Z].*$

You can use this and replace by empty string.See demo.

https://regex101.com/r/rX1tE6/5

Upvotes: 3

Avinash Raj
Avinash Raj

Reputation: 174706

Regex:

.*\\([0-9]+).*

Replacement string:

\1

or $1

DEMO

Upvotes: 1

Related Questions