Regular Expressions 101

Community Patterns

JavaScript Function w/ Recusive Parenthasis JavaScript Function w/ Recusive Parenthasis JavaScript Function w/ Recusive Parenthasis

0

Regular Expression
PCRE2 (PHP >=7.3)

/
([\w$]*[\w\d$]*?(\(\)|\(\g<0>\))?\.?)*
/
g

Description

Regex that allows the following:

foo(bar).qax(foo(bar).qax(foo(bar).qax(foo(bar).qax())))

Its sorta hard to make out whats going on, so I will just say it:

The function foo(bar).qax() is nested in itself recursively, like so foo(bar).qax(foo(bar).qax()) Which this regex permits. It also allows no digit as the first character and accepts underscores and dollarsigns in the syntax name. Can be used for objects w/ non-function property-members as well.

For example:

obj.foo.bar

hello.world.hello.world
a.b.c.d.e(a.b.c.d.e)
a.b.c.d.e(a.b.c.d.e(a.b.c.d.e(a.b.c.d.e())))
A(B(C().DEF()).ABC())

All the above will match

Submitted by jD3V - 2 years ago