How to get string between parthenses in regex?

I need help on getting a regex expression to get a string between ( )

Use your email () to login.

I need a regex expression that would get the email out. I can't seem to do it. Is it because of the ( )?

1

1 Answer

Depending on the program you're writing your regex for you'll have to use appropriate escaping. For example, with sed:

ts@xenon:~> echo 'Use your email () to login.' | sed -e 's/.*(\(.*\)).*/\1/'
ts@xenon:~>

In this case, the backslashes will escape the parentheses after them into metacharacters that extract the matched string between them into the metavariable \1 while the parentheses not preceded by a backslash will be matched literally.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like