Beta

RegEx Like a Boss #6: Valid Parenthesis

Description:

Create a Regular Expression that matches a string representing a valid parenthesis sequence. Three types of parenthesis will be used: () [] {}. The string could also contain alphanumeric characters and spaces.

The pypi regex engine will be used that is more powerful than re. Matching with regex.match()

Should match:

()
()()
(())
{}
[]
{()}
[]
[{()}]
[{}()]
   ()
a()
(a)
()a
a ( a ) a
a
          a

Should NOT match

(
)
)(
)()(
(()
(}
{]
{(})

Notes

  • empty strings or alphanumerics/spaces without parenthesis are valid matches
  • You´re RegEx should not be longer than 150 characters

This tools may help you:

Cheat sheet

Online tester

Mathematics
Regular Expressions
Strings
Fundamentals
Algorithms

Stats:

CreatedJan 7, 2019
PublishedJan 16, 2019
Warriors Trained130
Total Skips2
Total Code Submissions91
Total Times Completed9
Python Completions9
Total Stars8
% of votes with a positive feedback rating50% of 3
Total "Very Satisfied" Votes1
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • sgerodes Avatar
Ad