gpt4 book ai didi

regex - 忽略tmLanguage定义内的换行符

转载 作者:行者123 更新时间:2023-12-03 13:36:20 26 4
gpt4 key购买 nike

我有一个tmLanguage定义(用于笨拙的8088仿真器),并且某些正则表达式变得越来越大。

<string>\s*(?i)(%define|%ifndef|%xdefine|%idefine|%undef|%assign|%defstr|%strcat|%strlen|%substr|%00|%0|%rotate|%rep|%endrep|%include|\$\$|\$|%unmacro|%if|%elif|%else|%endif|%(el)?ifdef|%(el)?ifmacro|%(el)?ifctx|%(el)?ifidn|%(el)?ifidni|%(el)?ifid|%(el)?ifnum|%(el)?ifstr|%(el)?iftoken|%(el)?ifempty|%(el)?ifenv|%pathsearch|%depend|%use|%push|%pop|%repl|%arg|%stacksize|%local|%error|%warning|%fatal|%line|%!|%comment|%endcomment|__NASM_VERSION_ID__|__NASM_VER__|__FILE__|__LINE__|__BITS__|__OUTPUT_FORMAT__|__DATE__|__TIME__|__DATE_NUM__|_TIME__NUM__|__UTC_DATE__|__UTC_TIME__|__UTC_DATE_NUM__|__UTC_TIME_NUM__|__POSIX_TIME__|__PASS__|ISTRUC|AT|IEND|BITS16|BITS32|BITS64|USE16|USE32|__SECT__|ABSOLUTE|EXTERN|GLOBAL|COMMON|CPU|FLOAT|_STDOUT|_GETCHAR|_WRITE|_STDIN|_EXIT|\.SECT\.....?)\b?([_a-zA-Z][_a-zA-Z0-9]*)?</string>

我想,好吧,我将其分解成多行。
<string>\s*(?i)(
%define|%ifndef|%xdefine|%idefine|%undef|%assign|%defstr|%strcat
|%strlen|%substr|%00|%0|%rotate|%rep|%endrep|%include|\$\$|\$
|%unmacro|%if|%elif|%else|%endif|%(el)?ifdef|%(el)?ifmacro
|%(el)?ifctx|%(el)?ifidn|%(el)?ifidni|%(el)?ifid|%(el)?ifnum
|%(el)?ifstr|%(el)?iftoken|%(el)?ifempty|%(el)?ifenv|%pathsearch
|%depend|%use|%push|%pop|%repl|%arg|%stacksize|%local|%error
|%warning|%fatal|%line|%!|%comment|%endcomment
|__NASM_VERSION_ID__|__NASM_VER__|__FILE__|__LINE__|__BITS__
|__OUTPUT_FORMAT__|__DATE__|__TIME__|__DATE_NUM__|_TIME__NUM__
|__UTC_DATE__|__UTC_TIME__|__UTC_DATE_NUM__|__UTC_TIME_NUM__
|__POSIX_TIME__|__PASS__|ISTRUC|AT|IEND|BITS 16|BITS 32|BITS 64
|USE16|USE32|__SECT__|ABSOLUTE|EXTERN|GLOBAL|COMMON|CPU|FLOAT
|_STDOUT|_GETCHAR|_WRITE|_STDIN|_EXIT|\.SECT \.....?)\b ?([_a-zA-Z][_a-zA-Z0-9]*)?
</string>

除此之外,当我分解它时,正则表达式会尝试匹配例如 %strcat\n(在行的末尾添加了换行符)。

我不要

有没有办法在此保存的正则表达式中忽略换行符?

最佳答案

您可以使用RegexFormat应用程序http://www.regexformat.com来进行压缩和格式化

编辑,并进行一些重构,可能是这样

 # <string>\s*(?i)(%define|%ifndef|%xdefine|%idefine|%undef|%assign|%defstr|%strcat|%strlen|%substr|%00|%0|%rotate|%rep|%endrep|%include|\$\$?|%unmacro|%if|%elif|%else|%endif|(?:%(?:el)?(?:ifdef|ifmacro|ifctx|ifidn|ifidni|ifid|ifnum|ifstr|iftoken|ifempty|ifenv))|%pathsearch|%depend|%use|%push|%pop|%repl|%arg|%stacksize|%local|%error|%warning|%fatal|%line|%!|%comment|%endcomment|__NASM_VERSION_ID__|__NASM_VER__|__FILE__|__LINE__|__BITS__|__OUTPUT_FORMAT__|__DATE__|__TIME__|__DATE_NUM__|_TIME__NUM__|__UTC_DATE__|__UTC_TIME__|__UTC_DATE_NUM__|__UTC_TIME_NUM__|__POSIX_TIME__|__PASS__|ISTRUC|AT|IEND|BITS16|BITS32|BITS64|USE16|USE32|__SECT__|ABSOLUTE|EXTERN|GLOBAL|COMMON|CPU|FLOAT|_STDOUT|_GETCHAR|_WRITE|_STDIN|_EXIT|\.SECT\.....?)(?-i)\b?([_a-zA-Z][_a-zA-Z0-9]*)?</string>

<string>(?x) # Expanded mode (ignore whitespace) - first chars of the regex string
\s*
(?i)
( # (1 start)
%define
| %ifndef
| %xdefine
| %idefine
| %undef
| %assign
| %defstr
| %strcat
| %strlen
| %substr
| %0 0?
| %rotate
| %rep
| %endrep
| %include
| \$ \$?
| %unmacro
| %if
| %elif
| %else
| %endif
| %
(?: el )?
(?:
ifdef
| ifmacro
| ifctx
| ifidn
| ifidni
| ifid
| ifnum
| ifstr
| iftoken
| ifempty
| ifenv
)
| %pathsearch
| %depend
| %use
| %push
| %pop
| %repl
| %arg
| %stacksize
| %local
| %error
| %warning
| %fatal
| %line
| %!
| %comment
| %endcomment
| __NASM_VERSION_ID__
| __NASM_VER__
| __FILE__
| __LINE__
| __BITS__
| __OUTPUT_FORMAT__
| __DATE__
| __TIME__
| __DATE_NUM__
| _TIME__NUM__
| __UTC_DATE__
| __UTC_TIME__
| __UTC_DATE_NUM__
| __UTC_TIME_NUM__
| __POSIX_TIME__
| __PASS__
| ISTRUC
| AT
| IEND
| BITS16
| BITS32
| BITS64
| USE16
| USE32
| __SECT__
| ABSOLUTE
| EXTERN
| GLOBAL
| COMMON
| CPU
| FLOAT
| _STDOUT
| _GETCHAR
| _WRITE
| _STDIN
| _EXIT
| \.SECT\. . . . .?
) # (1 end)
(?-i)
\b?
( [_a-zA-Z] [_a-zA-Z0-9]* )? # (2)
</string>

关于regex - 忽略tmLanguage定义内的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20429496/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com