如何通过正则表达式匹配此表达式?

时间:2016-09-23 13:26:06

标签: regex

如何匹配以下行:

 SomeText SomeText SomeText SomeText SomeText 
SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText.
SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText.
SomeText SomeText :
SomeText SomeText SomeText SomeText SomeText SomeText  (BlockID: 12345,TestCaseID: 12345, 1)

我想要的是之前的整个部分(BlockID:12345,TestCaseID:12345,1) 我想要的另一部分是BlockID的12345,另一个是TestCaseID

我已尝试以下标记所有行,但我不知道:

(?:[^\n]*(\n*))+.*

2 个答案:

答案 0 :(得分:0)

直到BlockID的所有内容:

([\S\s]*)(?=\(BlockID)
来自BlockID的

12345:

(?:BlockID: )([0-9]{5})

12345,1来自TestCaseID:

(?:TestCaseID: )([0-9]{5}, [0-9])

答案 1 :(得分:0)

根据您的实际输入类型,我可以推荐类似

的内容
p1 = new Plyta(p1.ImtiIlgi(), p1.ImtiAuksti());

表示:

  • 捕获长度为1或更长的字符序列(包括我们将添加 public Plyta(){} 标志的新行),
  • 直到您到达int a = 1; int b = 2; Plyta p1; p1 = new Plyta(a, b);
  • 此时捕获一个或多个数字的序列,
  • 后跟(.+)\\(BlockID: (\\d+),TestCaseID: (\\d+), 1\\)
  • 然后再次捕获一个或多个数字的序列,
  • 后跟DOTAL

这是在工作中:

BlockID:

输出:

  

SomeText SomeText SomeText SomeText SomeText
  SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText。
  SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText SomeText。
  SomeText SomeText:
  SomeText SomeText SomeText SomeText SomeText SomeText
  12345个
  12345