tobeyt323 Posted February 9, 2017 Share Posted February 9, 2017 Find and match all parentheses with open and close and weed out any that dont match $string = "(()))(()"; How do i accomplish this? Quote Link to comment https://forums.phpfreaks.com/topic/303148-find-parentheses/ Share on other sites More sharing options...
Jacques1 Posted February 9, 2017 Share Posted February 9, 2017 (edited) Use a stack. Opening parentheses (or their indexes) get pushed onto the stack; whenever you encounter a closing paranthesis, you pop the stack. Is this homework? Edited February 9, 2017 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/303148-find-parentheses/#findComment-1542530 Share on other sites More sharing options...
requinix Posted February 9, 2017 Share Posted February 9, 2017 Weed out any strings that don't match? Match an opening parentheses, use (?R)* for recursion, and match a closing parenthesis, then check that what you found was the entire string. If you want to weed out any parentheses that don't match then it depends how you want to report on what didn't match... Quote Link to comment https://forums.phpfreaks.com/topic/303148-find-parentheses/#findComment-1542531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.