-4

As i'm really bad in REGEX, I'm looking for some help here. a string can be of the following two formats:

 1. id://3
 2. id://3/1

How can i check if one of the two formats is available (because there's e.g. id://next – id + strings – as well) and how can i extract in the first case the "3" and the second case the "3" and "1" in separate variables? the numbers can be anything (3,1 is just an example).

thanks in advance!

trnc
  • 20,581
  • 21
  • 60
  • 98

1 Answers1

1

You can use this regex:

\bid:\/.*?\/(\d+)\b(?!\/)

RegEx Demo

anubhava
  • 761,203
  • 64
  • 569
  • 643