Valid, and ONLY possible source string formats: (numbers and letters will vary)
- xxxx/xxxx/0884/11 (x corresponds to random letters)
- xxxx/xxxx/884/11 (x corresponds to random letters)
- 884/11
- 0884/11
- 7/11
Desired outputs after extraction (respectively):
- 0884
- 0884
- 0884
- 0884
- 0007
Can this be done a bit cleanly, with perhaps some regex?
Blah 🙂 the generic condition is: (
beginning of stringORcharacters than /) and after that1 to 4 numbers, the precondition in PCRE is:^|\w+/, numbers are:\d{1,4}.Joined together you will get this regexp:
~(^|\w+/)(\d{1,4})~which can be used withpreg_match()into this: