Snippets

Steven Berlan Bracket matching one liner in perl

Created by Steven Berlan last modified
1
2
3
4
5
# Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
# 
# The brackets must close in the correct order, "()", "([])" and "()[]{}" are all valid but "(]" and "([)]" are not.

echo '()([]{}(()))' | perl -ne 'exit !/^(\((?1)*\)|\[(?1)*\]|\{(?1)*\})+$/'

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.