-1

Given a fairly simple regex, I'd like to match a text between to delimiters:

___MANUAL_TICKET___

###_CLIENT_START_###
TEST
###_CLIENT_END_###

###_PROBLEM_START_###
TEST2
###_PROBLEM_END_###

###_EMAIL_START_###
xyz@test.com
###_EMAIL_END_###

To get the client I am using this regex:

###_CLIENT_START_###\s(.*?)\s###_CLIENT_END_###

which works as seen HERE.

But when I use it in my PHP Code it does not find any matches:

preg_match('@###_CLIENT_START_###\s(.*?)\s###_CLIENT_END_###@', $source, $matches);

(tried different regex delimiter such as / and ~, same result)

What am I doing wrong?

PrimuS
  • 2,085
  • 5
  • 25
  • 48

1 Answers1

1

Note that the dot (.) by default matches any symbol but the line feed (See the documentation).

Since you have multiple line input, you need to use the PCRE_DOTALL option, which can be enabled just adding symbol s at the very end of the pattern

preg_match('@###_CLIENT_START_###\s(.*?)\s###_CLIENT_END_###@s', $source, $matches);
                                                             ^ here 
AterLux
  • 3,708
  • 2
  • 8
  • 12