【问题标题】:How do you match multiple lines with dot (DOTALL) in eclipse find regex你如何在eclipse中用点(DOTALL)匹配多行查找正则表达式
【发布时间】:2014-10-25 03:47:33
【问题描述】:

我想转换这个:

  def getEmployeeReminders(employeeId: Int, page: Option[Int], pageSize: Option[Int], js_callback: Option[String]) = Action {
      val reminders = Reminder.listForOne(employeeId, page, pageSize)
      getResponse(reminders, js_callback)
    }

到这里:

  def getEmployeeReminders(employeeId: Int, page: Option[Int], pageSize: Option[Int], js_callback: Option[String]) =
    Restrict(companyAdmin, new MyDeadboltHandler) {
      Action {
        val reminders = Reminder.listForOne(employeeId, page, pageSize)
        getResponse(reminders, js_callback)
      }
    }

在 eclipse scala 编辑器中多次。

如何将多行与 '.*' 匹配? 另外,如何在替换中注入换行符?

【问题讨论】:

    标签: regex eclipse multiline


    【解决方案1】:

    您可以使用(?s) 内联模式修饰符,这将强制点. 也匹配换行符。在您的回答中,您使用的是否定字符类,因此无需使用此修饰符,只需使用 \n

    Find:    = (Action[^}]*})
    Replace: = \n    Restrict(companyAdmin, new MyDeadboltHandler) {\n     \1}
    

    改用点.

    Find:    (?s)= (Action.*?})
    Replace: = \n    Restrict(companyAdmin, new MyDeadboltHandler) {\n     \1}
    

    【讨论】:

    • 我尝试使用点而不是否定字符类。但是,这与我的预期块不匹配。相反,它匹配得比预期的要多,因为它默认为“贪婪”匹配。我怀疑有一种方法可以使用点并指定非贪婪,但我很着急。
    • 跟随.*? 将使它不贪婪。
    【解决方案2】:

    将以下内容放在“find”表达式的最开头:(?s) 另请注意,我们使用 \R 插入换行符:

    例子:

    find:      (?s)= (Action[^}]*})
    replace:   = \R    Restrict(companyAdmin, new MyDeadboltHandler) {\R     \1}
    

    这需要这样的东西:

      def getEmployeeReminders(employeeId: Int, page: Option[Int], pageSize: Option[Int], js_callback: Option[String]) = Action {
          val reminders = Reminder.listForOne(employeeId, page, pageSize)
          getResponse(reminders, js_callback)
        }
    

    并将其替换为:

      def getEmployeeReminders(employeeId: Int, page: Option[Int], pageSize: Option[Int], js_callback: Option[String]) =
        Restrict(companyAdmin, new MyDeadboltHandler) {
          Action {
            val reminders = Reminder.listForOne(employeeId, page, pageSize)
            getResponse(reminders, js_callback)
          }
        }
    

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2014-10-08
      • 1970-01-01
      • 2011-07-11
      • 2011-09-28
      • 1970-01-01
      • 2015-06-01
      相关资源
      最近更新 更多