【问题标题】:Change Square Brackets to Round Brackets将方括号更改为圆括号
【发布时间】:2021-10-12 08:30:06
【问题描述】:

想在 Notepad++ 中使用正则表达式查找/替换将小写文本上的方括号更改为圆括号(括号)

但不影响第一个字母为大写字母 A-Z 的方括号

括号可以跨越两行。试图显示示例,但论坛使其成为单行。必须使用双 CR

改变这个:

[indistinct chatter]

[indistinct chatter

across the room]

[Maya sighs]

[George yelling

from across the street]

到这里:

(indistinct chatter)

(indistinct chatter

across the room)

[Maya sighs]

[George yelling

from across the street]

尝试了一些变化来找到这个:[以前在 Hit & Run]

\[([a-z][\U\s]*)\]
\[([A-Za-z][A-Za-z\s]*)\]
\[([a-z][a-zA-Z\s]*)\]
\[([a-z][A-ZA-Z\s]*)\]
\[([A-Z][A-Za-z\s]*)\] .... thought this was gonna do it

找到此文字:[Ron groans]

未找到:[Previously on Hit & Run] 其 &,如何包含特殊字符?

当在表达式中使用大写字母时,如何找到小写字母?
查找:\[([^A-Z].+?)\]

【问题讨论】:

    标签: regex notepad++


    【解决方案1】:
    // must be all lower case:
    find:
    \[([a-z\s]*)\] 
    
    //or specifically only the first letter lowercase, allowing subsequent characters as uppercase:
    \[([a-z][A-Za-z\s]*)\] 
    
    Replace with:
     ($1)
    

    【讨论】:

    • Steve Tomlin@ 我注意到我的答案与您的答案完全相同,您只是忘了告诉您必须检查 Match-Case ,
    • @Steve Tomlin 和 Chris Doyle .....谢谢一堆....所有 3 种方法都很好用。希望有一天光会出现......哈哈
    【解决方案2】:

    您可以使用以下正则表达式查找以括号开头但不跟大写字符的内容,然后匹配任何字符,包括换行符“not greedy”,直到找到结束括号。我已经设置了“.matches new line”和“match case”标志

    \[([^A-Z].+?)\]
    

    【讨论】:

      【解决方案3】:

      试试:

      \[([a-z][\S\s]+?)\]
      

      替换为:

      ($1)
      

      演示:

      在:

      [indistinct chatter]
      
      [indistinct chatter
      
      across the room]
      
      [Maya sighs]
      
      [George yelling
      
      from across the street]
      

      输出:

      (indistinct chatter)
      
      (indistinct chatter
      
      across the room)
      
      [Maya sighs]
      
      [George yelling
      
      from across the street]
      

      【讨论】:

        猜你喜欢
        • 2020-07-17
        • 2021-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-12
        • 2014-10-13
        • 1970-01-01
        相关资源
        最近更新 更多