goelv
goelv

Reputation: 2884

How to capture a specific range of numbers within a larger string?

I have a 15-digit number followed by a number that can be any length.

For example:

15 digit number + 2 digit number;

15 digit number + 3 digit number;

15 digit number + 10 digit number;

How do I use RegEx to capture the first 15 digits as "Part 1" and the remaining number of digits as "Part 2"?

Upvotes: 0

Views: 73

Answers (1)

Mark Byers
Mark Byers

Reputation: 837986

Try this regular expression:

^(\d{15})(\d+)$

Explanation:

^      Start of string
$      End of string
\d     Any digit
{15}   Repeat 15 times
+      Repeat one or more times.
(...)  Capturing group

Upvotes: 1

Related Questions