Regular Expressions 101

Community Patterns

Fetch "text A (text B)" or "text A (text B (text C))"

1

Regular Expression
PCRE2 (PHP >=7.3)

/
(\b[^()]+\b)\s*\(\s*(\b[^()]+\b)\s*\)
/
gm

Description

How do I extract then some text A, some text B and some text C if they are in the format

some text A ( some text B ( some text C)) Please mind that in some cases may be only

some text A ( some text B)

https://stackoverflow.com/questions/69047224/how-to-fetch-text-strings-in-regex-in-the-format-abc

Submitted by anonymous - 2 years ago