RegEx忽略注释行。(RegEx Ignore a commented line.)
我试图解析以下文本
# ---------------------------------------------------------------------------- # # Packages # ---------------------------------------------------------------------------- # set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_1_test_1_qip.vhd"] set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_2_test_1_qip.vhd"] set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_3_test_1_qip.vhd"] # Register Tool set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_INVALID_test_1_qip.vhd"] # ---------------------------------------------------------------------------- # # Sub Modules # ---------------------------------------------------------------------------- # set_global_assignment -name QIP_FILE [file join $::quartus(qip_path) "module_test_2.qip"] set_global_assignment -name QIP_FILE [file join $::quartus(qip_path) "module_test_3.qip"] # ---------------------------------------------------------------------------- # # Module Files # ---------------------------------------------------------------------------- # set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_4_test_1_qip.vhd"] set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_5_test_1_qip.vhd"]使用正则表达式:
(?<=_FILE).*"(.+)"这也工作正常,并给我上面的文本中的所有文件名,但它也给了我已注释掉的行的文件名。
我试图制作一个会忽略它的RegEx但是我无法让它工作。
这就是我尝试过的
(?<!#)(?:(?<=_FILE).+"(.+)")请查看RegEx 101
关心Ephreal
I am trying to parse the following text
# ---------------------------------------------------------------------------- # # Packages # ---------------------------------------------------------------------------- # set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_1_test_1_qip.vhd"] set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_2_test_1_qip.vhd"] set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_3_test_1_qip.vhd"] # Register Tool set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_INVALID_test_1_qip.vhd"] # ---------------------------------------------------------------------------- # # Sub Modules # ---------------------------------------------------------------------------- # set_global_assignment -name QIP_FILE [file join $::quartus(qip_path) "module_test_2.qip"] set_global_assignment -name QIP_FILE [file join $::quartus(qip_path) "module_test_3.qip"] # ---------------------------------------------------------------------------- # # Module Files # ---------------------------------------------------------------------------- # set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_4_test_1_qip.vhd"] set_global_assignment -name VHDL_FILE [file join $::quartus(qip_path) "file_5_test_1_qip.vhd"]Using the regex:
(?<=_FILE).*"(.+)"This also works fine and gives me all the file names in text above, however it also gives me the file names of lines which have been commented out.
I've tried to make a RegEx which would ignore this however I cannot get it to work.
This is what I've tried
(?<!#)(?:(?<=_FILE).+"(.+)")Please take a look at the RegEx 101
Regards Ephreal
最满意答案
要忽略注释行,您必须在行的开头匹配并匹配除#任何内容:
^[^#\n]*(?:(?<=_FILE).+"(.+)")要不就
^[^#\n]*_FILE.+"(.+)"两种模式都需要多线标志m 。
To ignore commented lines, you have to start matching at the start of the line and match anything but #:
^[^#\n]*(?:(?<=_FILE).+"(.+)")Or just
^[^#\n]*_FILE.+"(.+)"Both patterns need the multiline flag m.
更多推荐
发布评论