简体   繁体   中英

grep capture python function definition

I have tried:

$ grep -Po "def[[:space:]]+\K(.*)\(" code.py

The output should be a list of function names.

I think it should be correct, but it's only capturing one extra bracket. I would like to get rid off it in the expression (not postprocessing). Please, explain the syntax, you will use.

您可以通过将结果字符串放在先行(?=<expression>)来省略“(” (?=<expression>)

grep -Po "def[[:space:]]+\K(.*)(?=\()" code.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM