【发布时间】:2017-07-08 16:43:03
【问题描述】:
有人可以帮我写 single 正则表达式以从 python 源代码行获取模块吗?
from abc.lmn import pqr
from abc.lmn import pqr as xyz
import abc
import abc as xyz
里面有3个子部分
[from(\s)<module>(\s)] --> get module if this part exist
import(\s)<module> --> get module
[(\s)as(\s)<alias>] --> ignore if this part exist
类似的东西
:?[from(\s)<module>(\s)]import(\s)<module>:?[(\s)as(\s)<alias>]
【问题讨论】:
-
你应该基于the grammar。