我有一个带反向引用的正则表达式。如何在bash脚本中使用它?
例如,我想打印与(.*)匹配的内容
grep -E "CONSTRAINT \`(.*)\` FOREIGN KEY" temp.txt 如果将其应用于
CONSTRAINT `fk_dm` FOREIGN KEY我想输出
fk_dm发布于 2012-01-11 19:58:51
$ 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 发布于 2012-01-11 19:53:37
grep -E 'CONSTRAINT \`(.*)\` FOREIGN KEY' temp.txt https://stackoverflow.com/questions/8818747
复制相似问题