简体   繁体   English

正则表达式过滤器换行搜索

[英]Regex Filter Newline Search

I need to filter the query from a log and it needs look up the newlines and i have stuck in regex filtering the new lines 我需要从日志中过滤查询,它需要查找换行符,并且我坚持使用正则表达式过滤新行

here is the example of the log that i want to filter 这是我想要过滤的日志的示例

      139 Connect   root@localhost as anonymous on 
      139 Query SET CHARACTER SET 'utf8mb4'
      139 Query SET collation_connection = 'utf8mb4_unicode_ci'
      139 Query SELECT CURRENT_USER()
      139 Query FLUSH PRIVILEGES
      139 Query SELECT * FROM `mysql`.`db` LIMIT 1
      139 Query DELETE FROM `mysql`.`db` WHERE `host` = "" AND `Db` = "" AND `User` = "" LIMIT 1
      139 Query INSERT INTO `mysql`.`db`(`host`, `Db`, `User`) VALUES("pma_test_host", "mysql", "pma_test_user")
      139 Query DELETE FROM `mysql`.`db` WHERE host = "pma_test_host" AND Db = "mysql" AND User = "pma_test_user" LIMIT 1
      139 Query UPDATE `mysql`.`db` SET `host` = "" WHERE `host` = "" AND `Db` = "" AND `User` = "" LIMIT 1

from that log text i have used regex like this 从那个日志文本我已经使用了这样的正则表达式

(?=Query).*

but the search result only in a line 但搜索结果只有一行

Query   SET CHARACTER SET 'utf8mb4'

because i use the character of "." 因为我使用“。”的字符。 in regex which mean not doing search in a new line. 在正则表达式中,这意味着不在新行中搜索。 i've tried to put "\\n" in few way but it doesn't work. 我试图以一些方式放置“\\ n”,但它不起作用。 i need a suggestion to get result like this: 我需要一个建议来得到这样的结果:

Query   SET CHARACTER SET 'utf8mb4'
          139 Query SET collation_connection = 'utf8mb4_unicode_ci'
          139 Query SELECT CURRENT_USER()
          139 Query FLUSH PRIVILEGES
          139 Query SELECT * FROM `mysql`.`db` LIMIT 1
          139 Query DELETE FROM `mysql`.`db` WHERE `host` = "" AND `Db` = "" AND `User` = "" LIMIT 1
          139 Query INSERT INTO `mysql`.`db`(`host`, `Db`, `User`) VALUES("pma_test_host", "mysql", "pma_test_user")
          139 Query DELETE FROM `mysql`.`db` WHERE host = "pma_test_host" AND Db = "mysql" AND User = "pma_test_user" LIMIT 1
          139 Query UPDATE `mysql`.`db` SET `host` = "" WHERE `host` = "" AND `Db` = "" AND `User` = "" LIMIT 1

You may use a regex like 你可以使用正则表达式

(?=Query)[\s\S]*

It will check if there is Query immediately to the left of the current location and then will consume (will put to the match value) any 0+ chars (including line breaks). 它将检查当前位置左侧是否有Query ,然后将消耗(将匹配值)任何0+字符(包括换行符)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM