Regular Expressions 101

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

Open Workspace
  • PCRE (Legacy)
  • Match
0

Regular Expression

/
(?<!\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