Regular Expressions 101

Community Patterns

Capture the last space in a line of text with Negative Lookback

1

Regular Expression
PCRE (PHP <7.3)

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

Description

Looks for the last single space in a line of text.

Submitted by anonymous - 7 years ago