Skip to content

Instantly share code, notes, and snippets.

@rabestro
Last active March 16, 2023 21:35
Show Gist options
  • Save rabestro/9751877484d06999d953b8956ee17660 to your computer and use it in GitHub Desktop.
Save rabestro/9751877484d06999d953b8956ee17660 to your computer and use it in GitHub Desktop.
Matching Brackets

Given a string containing brackets [], braces {}, parentheses (), or any combination thereof, verify that any and all pairs are matched and nested correctly.

How to run

sed -Enf parentheses.sed parentheses.txt

Output

true
true
true
false
false
true
false
true
false
:do
s/\(\)|\{\}|\[\]|[^][(){}]//g
t do
s/^$/true/p
t
s/.*/false/p
[()[]{}]{}
[][]()
()
))((
{)
(()())
))
()
)()(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment