Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
(?<!\s)(\s\S+?)(?:\r\n?|\n|\z)
/
g

Description

Looks for and captures the last single space and the last word in a line of text that is terminated by \r\n, \n or anchored to the back.

Submitted by James Dafferner - 7 years ago