正则表达式搜索多个字符串(Textpad)

gfu*_*r40 38 regex textpad

我对正则表达式有点新意,我正在寻找一些通配符字符串的多行/实例,例如*8768,*9875,*2353.

我想拉出这些实例(在一个文件中),而不是单独搜索它们.

任何帮助是极大的赞赏.我尝试过像*8768,*9875等等......

wal*_*lyk 54

如果我明白你在问什么,那就是这样的正则表达式:

^(8768|9875|2353)
Run Code Online (Sandbox Code Playgroud)

这仅匹配行首的三组数字字符串.


acd*_*ior 32

要获取包含文本的行8768,9875或者2353使用:

^.*(8768|9875|2353).*$
Run Code Online (Sandbox Code Playgroud)

这是什么意思:

^                      from the beginning of the line
.*                     get any character except \n (0 or more times)
(8768|9875|2353)       if the line contains the string '8768' OR '9875' OR '2353'
.*                     and get any character except \n (0 or more times)
$                      until the end of the line
Run Code Online (Sandbox Code Playgroud)

如果你想要文字*字符,你必须逃避它:

^.*(\*8768|\*9875|\*2353).*$
Run Code Online (Sandbox Code Playgroud)

  • `^.(*01 | 04 | 08).*$`错了.在我的答案中使用一个或改变`*`的位置(将它拉出`()`s),如下所示:`^.*(01 | 04 | 08).*$`. (2认同)