2

My attempt

preg_match("/^logs.\d{24}.\d{24}.{4}$/", $input_line, $output_array);
If matched return \d{24} in echo

String

logs/532523532543353444444444/532523532543353444444444.log

Preg match peseudo-code : logs/{24 digitals}/{same24digits}.log

Both \d{24} are the same number

Question How to get the : If matched return \d{24} in echo

2 Answers 2

2

You can use:

if (preg_match('~^logs/(\d{24})/\1\.log$~', $input_line, $m))
   echo $m[1];

\1 ia back-reference to first captured group i.e. (\d{24})

Code Demo

Sign up to request clarification or add additional context in comments.

1 Comment

Ok so the $m[1] result is 893259838902389058903258/893259838902389058903258.log I just need the number 893259838902389058903258
2
logs\/(\d{24})\/\1.log

see demo http://regex101.com/r/hU0uS6/1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.