【问题标题】:Regex excluding LineBreak and Spaces正则表达式不包括换行符和空格
【发布时间】:2015-05-19 17:43:09
【问题描述】:

这是我第一次真正需要编写任何正则表达式,但我相当迷茫。我需要找到与以下示例匹配的项目,其中 * 中的任何内容都可能发生变化。还有一些类似的记录,但没有我不想选择的换行符和空格。空格的数量可以变化。如果有人可以提供帮助,那就太好了!以下是我希望搜索的示例:


inspect *DX-DATA-EX1*(*0000411*:*0000002*)
                                        converting E-NUMB to A-NUMB

如果我最初的帖子太含糊(这里的第一篇帖子,不确定要包括什么),我很抱歉造成混乱,所以我有上述行。我需要以下(伪代码):

*anything*(*anything*)*newline* converting E-NUMB to A-NUMB  

希望这会更有帮助吗? :$
我只是想使用 RegEx 选项在 Notepad++ 中搜索文本文件。

【问题讨论】:

  • 请张贴清晰的输入/输出样本。即:“我有这个”和“我需要这个”。
  • 还有你想用什么语言使用这个正则表达式?

标签: regex regex-negation regex-lookarounds regex-greedy


【解决方案1】:

如果我理解正确,你的输入字符串应该匹配这个正则表达式:

^[^\(]*\([^\)]*\)(\r\n?|\n\r?)+ +converting E-NUMB to A-NUMB$

解释:

^      The beginning of the string
[^\(]* Any characters at all (including new line) that are not an opening `(`
\(     An opening `(`, escaped so that it is treated at its real value
[^\)]* Any characters that are not a closing `)`
\)     A closing `)`, escaped so that it is treated at its real value
(\r\n?|\n\r?)+  Any combination of carriage return and line feed, one or more times
 +     At least one space 
converting E-NUMB to A-NUMB  Exactly these characters
$      The end of the string

Online tester

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多