Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用正则表达式解析java中的INNODB状态_Java_Regex - Fatal编程技术网

用正则表达式解析java中的INNODB状态

用正则表达式解析java中的INNODB状态,java,regex,Java,Regex,我试图用正则表达式解析java中的INNODB状态。我试图提取有关死锁的信息。我正试图获取与死锁相关的信息。我使用下面的正则表达式来获取与最近检测到的死锁相关的文本块 String innodbStatus = <required_INNODB_status>; // assume this is the text String multiLineRegEx = "((.*)(?:(?:\r\n|[\r\n]))*)*"; String newLineCharacter = Sys

我试图用正则表达式解析java中的INNODB状态。我试图提取有关死锁的信息。我正试图获取与死锁相关的信息。我使用下面的正则表达式来获取与最近检测到的死锁相关的文本块

String innodbStatus =  <required_INNODB_status>; // assume this is the text
String multiLineRegEx = "((.*)(?:(?:\r\n|[\r\n]))*)*";
String newLineCharacter = System.getProperty("line.separator");
String myRegEx = "[-]+" + newLineCharacter + deadLockLabel + newLineCharacter + "[-]+" +  newLineCharacter + multiLineRegEx + "[-]+";

assertTrue(innodbStatus.matches(myRegEx));
关于如何提取所需文本的任何建议。 示例INNODB状态,我正在尝试解析它

=====================================
130502 14:18:59 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 27 seconds
------------------------
LATEST DETECTED DEADLOCK
------------------------
060717  4:16:48
*** (1) TRANSACTION:
TRANSACTION 0 42313619, ACTIVE 49 sec, process no 10099, OS thread id 3771312 starting index read
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 320
MySQL thread id 30898, query id 100626 localhost root Updating
update iz set pad='a' where i=2
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 16403 n bits 72 index `PRIMARY` of table `test/iz` trx id 0 42313619 lock_mode X locks rec but not gap waiting
Record lock, heap no 5 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
 0: len 4; hex 80000002; asc     ;; 1: len 6; hex 00000285a78f; asc       ;; 2: len 7; hex 00000040150110; asc    @   ;; 3: len 10; hex 61202020202020202020; asc a         ;;

*** (2) TRANSACTION:
TRANSACTION 0 42313620, ACTIVE 24 sec, process no 10099, OS thread id 4078512 starting index read, thread declared inside InnoDB 500
mysql tables in use 1, locked 1
3 lock struct(s), heap size 320
MySQL thread id 30899, query id 100627 localhost root Updating
update iz set pad='a' where i=1
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 0 page no 16403 n bits 72 index `PRIMARY` of table `test/iz` trx id 0 42313620 lock_mode X locks rec but not gap
Record lock, heap no 5 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
 0: len 4; hex 80000002; asc     ;; 1: len 6; hex 00000285a78f; asc       ;; 2: len 7; hex 00000040150110; asc    @   ;; 3: len 10; hex 61202020202020202020; asc a         ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 16403 n bits 72 index `PRIMARY` of table `test/iz` trx id 0 42313620 lock_mode X locks rec but not gap waiting
Record lock, heap no 4 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
 0: len 4; hex 80000001; asc     ;; 1: len 6; hex 00000285a78e; asc       ;; 2: len 7; hex 000000003411d9; asc     4  ;; 3: len 10; hex 61202020202020202020; asc a         ;;

*** WE ROLL BACK TRANSACTION (2)

----------
SEMAPHORES
----------

在找到一个可接受的标题/前缀开始匹配后,您的正则表达式似乎正在尝试匹配和捕获由破折号组成的行之间的文本(死锁标签-假设初始化为类似于
最新检测到的死锁,因为代码中缺少它)

我建议如下:

  • [-]+
    更改为仅
    -+
    -这些[]是多余的
  • +newLineCharacter
    添加到正则表达式的末尾,以便要捕获的文本位于仅为-的整行之间,而不仅仅是恰好出现在行首某处的-序列
  • 理想情况下,通过传递
    多行
    标志,将newLineCharacter的使用替换为^和$
  • 将用于捕获文本的正则表达式替换为类似以下内容的正则表达式:
    ((?:.*(:\r\n |\r |\n))+?)
    (请注意+运算符的不可用性),或者更好的做法是,只使用
    (.+?)
    并传递
    DOTALL
    标志
得到的优化正则表达式如下所示:

^-{4,}+(?:\r\n|\r|\n)LATEST DETECTED DEADLOCK(?:\r\n|\r|\n)-{4,}+(?:\r\n|\r|\n)(.+)-{4,}+$

我坚持破折号行的长度至少为4行,以计数并告诉它对使用破折号有占有欲,并且上面要求传递
多行
DOTALL
标志。

此文本中哪些行是重要的?死锁时间和死锁中涉及的事务(ID和查询)。。我首先尝试获取死锁信息的文本。下一步是从文本中提取这些信息。。还是直接从整个innodb状态中提取这些信息更好。。?
^-{4,}+(?:\r\n|\r|\n)LATEST DETECTED DEADLOCK(?:\r\n|\r|\n)-{4,}+(?:\r\n|\r|\n)(.+)-{4,}+$