I'm trying to use regex to grab the last 3 digits of a string that varies in size. The beginning of the string always leads with name- Examples:
"Name-0000425" "Name-00123" "Name-123"
I want the regex to grab the last 3 digits of this number and replace it with these digits. This is the regex I have tried but it only grabs the first 3 digits.
(?-s)(?<=Name-)(\d{3})
Any help would be appreciated! Thanks!
You can use
(?<=Name-)\d*(\d{3})
Replace with $1
. See the regex demo.
Alternatively, you may also use (Name-)\d*(\d{3})
and replace with $1$2
.
Details
(?<=Name-)
- a positive lookbehind that matches a location immediately preceded with Name-
\d*
- any zero or more digits(\d{3})
- Group 1 ($1
refers to this value from the replacement pattern): three digits.NOTES
(?<=Name-)0+(\d{3})
regex.(?<=Name-).*(\d{3})
.(?<=Name-)[^"\n\r]*(\d{3})
.