I have a string which contains a case id.
Example strings:
[Case 123]
lorem[Case 123]ipsum
[Case 123]ipsum
I want to get the id (123) from the string.
I tried (on string [Case 1359] needsmoreinfo):
$pattern = '/[Case (\d+)]/';
preg_match($pattern, $message->subject, $matches, PREG_OFFSET_CAPTURE);
Which resulted in:
o[0][0]: C
[1]: 1
Not really what I was looking for 🙂
What should the pattern look like, or is there another flaw somewhere?
[and]are characters with special meaning in regular expressions. You need to escape them to tell the regex engine to search for literal[and]characters:See more on what these characters do when unescaped: regular expression character classes.