1

Looking for a bit of regular expression help using PHP. What is the regex for the following:

EXACTLY {{file: THEN 24 characters from a-zA-Z0-9 THEN EXACTLY }}

Example:

{{file:504c2ee3ff558cb40700000b}}

Looking to match that pattern. Thanks much.

4
  • And please show what you've tried so far, and how it fails to do the task you're after. Commented Sep 9, 2012 at 7:13
  • Really you should say what programming language you are using. Regular expressions differ in the fundamentals and in the details between languages. I'm sure once you tell us it's easyBasic or Q# you will get a quick answer. Commented Sep 9, 2012 at 7:14
  • @LinusKleen the language is PHP. Thanks. Commented Sep 9, 2012 at 7:14
  • ^\{\{file:[a-zA-Z0-9]{24}\}\}$ should do it in most RegEx dialects. Commented Sep 9, 2012 at 7:15

2 Answers 2

2

Try:

preg_match_all('/\{\{file:[a-zA-Z\d]{24}\}\}/', $str, $matches);
Sign up to request clarification or add additional context in comments.

4 Comments

Shouldn't it be: preg_match_all('/\{\{file:[a-zA-Z0-9]{24}\}\}/i', $str, $matches);
@Justin The i modifier means case insensitive, So you don't need to write A-Z
The i modifier would make the "file" part case insensitive, as well.
personally I would spell out A-Z rather than rely on /i - which looks a bit hidden.
0

Try this,

preg_match_all('((\{{2})file:([a-z0-9]){24}(\}{2})/i', $str, $matches);

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.