Regular Expressions 101

Community Patterns

Brackets

0

Regular Expression
PCRE (PHP <7.3)

/
^( (?:\((?:[^()[\]{}]*|(?1))*\)) | (?:\[(?:[^()[\]{}]*|(?1))*\]) | (?:\{(?:[^()[\]{}]*|(?1))*\}) | [^()[\]{}]* )*$
/
gmx

Description

Task from check.io.

You are given an expression with numbers, brackets and operators. For this task only the brackets matter. Brackets come in three flavors: "{}" "()" or "[]". Brackets are used to determine scope or to restrict some expression. If a bracket is open, then it must be closed with a closing bracket of the same type. The scope of a bracket must not intersected by another bracket. In this task you should make a decision, whether to correct an expression or not based on the brackets.

Submitted by anonymous - 6 years ago