How do you match multiple lines with dot (DOTALL) in eclipse find regex

独自空忆成欢 提交于 2019-12-02 00:21:58

问题


I would like to convert this:

  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)
    }

to this:

  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)
      }
    }

Multiple times in eclipse scala editor.

How do you match multiple lines with a '.*' ? Also, how do you inject newline into replacement?


回答1:


You can use the (?s) inline mode modifier which will force the dot . to match newline characters as well. In your answer, you are using a negated character class so there is no need to use this modifier, and simply use \n

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

Using the dot . instead:

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



回答2:


place the following at very beginning of the 'find' expression: (?s) also note, we use \R to insert a newline:

Example:

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

This takes something like this:

  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)
    }

And replaces it with this:

  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)
      }
    }


来源:https://stackoverflow.com/questions/25596950/how-do-you-match-multiple-lines-with-dot-dotall-in-eclipse-find-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!