Regular Expressions 101

Community Patterns

Sentence and word validator

1

Regular Expression
PCRE (PHP <7.3)

/
^(?:(?<S>((?<W>[^\x20\.\r\n\(\)]*)\x20)*\g<W>\.|\(\g<W>((\x20\g<W>)*)?\))(\x20\g<S>)*)?$
/
gm

Description

Last captured word available via group W. Last captured sentence available via group S. Last parenthesis stuff in 6th capturing group.

Submitted by luis140219 on GitHub - 9 years ago