1

... i.e. NOT to match "end of line".

$ in PHP matches "end of line". This includes when you have the "m" flag.

But what if you have a multi-line string and you want to match the very end of it (or for that matter the very beginning)

I've done quite a bit of searching before daring to pose this question: searched the regex FAQ at SO, etc. Also studied quite carefully the functioning of the various PHP regex modifiers here. In particular, on that page, I thought I had found the answer with the "D" modifier: "If this modifier is set, a dollar metacharacter in the pattern matches only at the end of the subject string... ".

But ... if you read further in that para it then says: "This modifier is ignored if m modifier is set." (the "m" modifier is the "multi-line" modifier).

So... I'm confused, flummoxed, etc. '/Help!/'

mike rodent
  • 14,126
  • 11
  • 103
  • 157
  • 1
    Use `\z` or `\Z`: *The `\Z` is similar, but with the end of the value. However, it will also match before a newline at the end of the value. If you don't want this behaviour, use `\z`, which matches only at the end of the value.* – Wiktor Stribiżew Nov 17 '17 at 18:48
  • Thanks very much ... surprisingly elusive! – mike rodent Nov 17 '17 at 18:50

0 Answers0