[英]emacs: regexp matching to extract number from a string
I am trying to match only the numbers after the following strings: 我正在尝试仅匹配以下字符串之后的数字:
sequentialGrid: 650274
parallelGrid: 650274
My goal is to highlight the numbers, via Mx highlight-regexp
after lines beginning with sequentialGrid:
and parallelGrid:
我的目标是在以
Mx highlight-regexp
sequentialGrid:
和parallelGrid:
开头的行之后通过Mx highlight-regexp
突出显示数字parallelGrid:
Here was my attempt, using a Perl-like approach: 这是我的尝试,使用类似Perl的方法:
^sequentialGrid: \([0-9]*\).*/$1/
Unfortunately, Emacs does not support Perl functionality. 不幸的是,Emacs不支持Perl功能。 Thus, I hope my request is not impossible or perhaps someone can offer a convenient workaround.
因此,我希望我的请求不是没有可能,或者有人可以提供一个方便的解决方法。
BTW I verified that ^sequentialGrid: \\([0-9]*\\).*
highlights the entire line. 顺便说一句,我验证了
^sequentialGrid: \\([0-9]*\\).*
突出显示了整行。 I just need to extract the number. 我只需要提取数字。
If your goal is to add font-lock highlighting, the following expression will work: 如果您的目标是添加字体锁定突出显示,则以下表达式将起作用:
(font-lock-add-keywords
nil
'(("^\\(parallel\\|sequential\\)Grid:\\s-*\\([0-9]+\\)"
2 font-lock-warning-face)))
The nil
MODE parameter in it to the current buffer, or you could specify the mode name as a symbol. 其中的
nil
MODE参数为当前缓冲区,或者您可以将模式名称指定为符号。 See the manual and the wiki for more on font-lock-add-keywords
and font-lock-remove-keywords
. 有关
font-lock-add-keywords
和font-lock-remove-keywords
更多信息,请参见手册和Wiki 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.