Regular Expressions 101

Community Patterns

Capture the last word and space preceding it n a line of text with Negative Look-back

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