If I have a string like this:
FOO[BAR]
I need a generic way to get the ‘BAR’ string out of the string so that no matter what string is between the square brackets it would be able to get the string.
e.g.
FOO[DOG] = DOG FOO[CAT] = CAT
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should be able to use non-greedy quantifiers, specifically *?. You’re going to probably want the following:
This will give you a pattern that will match your string and put the text within the square brackets in the first group. Have a look at the Pattern API Documentation for more information.
To extract the string, you could use something like the following: