For JavaScript, how to use regex to extract content from the a square bracket?
example:
var str ='1.2.3.4 - - [01/Dec/2011:11:14:42 -0800]'
var result = str.match('\[.?*\]');
the input '\[.?*\]' does not work for me even with \ [ \ ]
Thanks!
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.
Try this:
The content of
[]will be captured by backreference$1. Use the lazy quantifier when doing this kind of extraction. Otherwise if you had two sets of brackets :[asdfjhasdf][asdfafas]you would only get one of them from the first[to the last]