I have a regular expression with a backreference. How can use it in a bash script?
Such as I want to print what matches to (.*)
grep -E "CONSTRAINT \`(.*)\` FOREIGN KEY" temp.txt 
If apply it to
CONSTRAINT `fk_dm` FOREIGN KEY
I want to output
fk_dm
                $ echo 'CONSTRAINT `helloworld` FOREIGN KEY' | grep -oP '(?<=CONSTRAINT `).*(?=` FOREIGN KEY)'
helloworld
-o, --only-matching       show only the part of a line matching PATTERN
-P, --perl-regexp         PATTERN is a Perl regular expression
(?=pattern)
    is a positive look-ahead assertion
(?!pattern)
    is a negative look-ahead assertion
(?<=pattern)
    is a positive look-behind assertion
(?<!pattern)
    is a negative look-behind assertion 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With