I have a string in Perl like: “Full Name (userid)” and I want to return just the userid (everything between the “()“‘s).
What regular expression would do this in Perl?
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.
This will match any word (
\w) character inside of “(” and “)“\wmatches a word character (alphanumeric or _), not just[0-9a-zA-Z_]but also digits and characters from non-roman scripts.If you need it in a
s///, you can get at the variable with$1or\1.If you want to capture all possibilities these would work better:
If your regexp starts to get complicated, I would recommend you learn about the
/xoption.Please see
perldoc perlre, for more information.If you are just beginning to learn regexps, I would recommend reading
perldoc perlretut.