Please enable JavaScript to use regex101
/
^
r
e
g
e
x
[
\
-
_
]
?
1
0
1
$
/
i
Regular
Expressions
101
Regular
Expressions
101
Upgrade to Pro
Enterprise
Regular Expression
~
(?(DEFINE) # Start of definitions (?P<str_double_quotes> (?<!\\) # Not escaped " # Match a double quote (?: # Non-capturing group [^\\] # Match anything not a backslash | # Or \\. # Match a backslash and a single character (ie: an escaped character) )*? # Repeat the non-capturing group zero or more times, ungreedy/lazy " # Match the ending double quote ) (?P<str_single_quotes> (?<!\\) # Not escaped ' # Match a single quote (?: # Non-capturing group [^\\] # Match anything not a backslash | # Or \\. # Match a backslash and a single character (ie: an escaped character) )*? # Repeat the non-capturing group zero or more times, ungreedy/lazy ' # Match the ending single quote ) (?P<brackets> \( # Match an opening bracket (?: # A non capturing group (?&str_double_quotes) # Recurse/use the str_double_quotes pattern | # Or (?&str_single_quotes) # Recurse/use the str_single_quotes pattern | # Or [^()] # Anything not a bracket | # Or (?&brackets) # Recurse the bracket pattern )* \) ) ) # End of definitions # Let's start matching for real now: _n? # Match _ or _n \s* # Optional white spaces (?P<results>(?&brackets)) # Recurse/use the brackets pattern and put it in the results group
~
sxg
Test String
New
_ ("foo") // want "foo" _n("bar", "baz", 42); // want "bar", "baz", 42 _n(domain, "bux", var); // want domain, "bux", var _( "one (optional)" ); // want "one (optional)" apples === 0 ? _( "No apples" ) : _n("%1 apple", "%1 apples", apples) // could have on the same line two calls.. // misleading cases _n("foo (") _n("foo (\)", 'foo)', aa) _n( Array(1, 2, 3), Array(")", '(') ); _n(function(foo){return foo*2;}); // Is this even valid? _n (); // Empty _ ( "Foo", 'Bar', Array( "wow", "much", 'whitespaces' ), multiline ); // PCRE is awesome