Regular Expressions 101

Community Patterns

Array-like string

0

Regular Expression
ECMAScript (JavaScript)

/
^\[ *(((['"][-\w. ]+['"]|[-\w.]+), *)*)(['"][-\w. ]+['"]|[-\w.]+) *]$
/

Description

Matches strings that are formatted as arrays.

The following will match:

  • [ 3.4, -600, foo ]
  • ["foo","bar"]
  • [ bar, 1600 ]
  • [ foo ]
  • `[ "foo bar" ]

But these won’t match:

  • 3.4, -600, foo
  • [ "foo" "bar" ]
  • [ foo bar ]
Submitted by Chris Swithinbank - 7 years ago