I need to find the regex for []
For eg, if the string is – Hi [Stack], Here is my [Tag] which i need to [Find].
It should return
Stack, Tag, Find
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.
Pretty simple, you just need to (1) escape the brackets with backslashes, and (2) use
(.*?)to capture the contents.The parentheses are a capturing group, they capture their contents for later use. The question mark after
.*makes the matching non-greedy. This means it will match the shortest match possible, rather than the longest one. The difference between greedy and non-greedy comes up when you have multiple matches in a line:A greedy match will find the longest string possible between two sets of square brackets. That’s not right. A non-greedy match will find the shortest:
Anyways, the code will end up looking like: