2017-05-08 70 views
-1

工作我有以下的正則表達式正則表達式沒有在Java

[0-9]+[a-zA-Z]+[ ]([a-zA-Z]+[ ]+){0,10}+[0-9]+ 

//代碼以匹配從哪裏得到(1)=的字符串。它並不需要匹配整個事情只是(59Hello軸只有5454XXX6334 1233333)和(59World 58123612344501)

if (list.get(i).matches("[0-9]+[a-zA-Z]+[ ]([a-zA-Z]+[ ]+){0,10}+[0-9]+")) { 
            System.out.println(list.get(i)); 
           } 

要符合以下

59Hello Axis Only 5454XXX6334 1233333 0.00%R596.11 R12,180.12 R210.880.00%321 58R0.00 R0.00 
59World 58123612344501 0.00%R389.06 R9,337.52 R161.840.00%242 58R0.00 R0.00 

它應與這兩個線。任何幫助,提高了正則表達式將有助於

+2

您能否提供更多詳細信息?字符串[*爲*匹配](https://regex101.com/r/7ueVCC/1),但不完整。你使用'matches()'?使用'find()'。 –

+0

它可以幫助我們,如果你可以分享你用來測試你的正則表達式的代碼。 –

+0

使用'String#matches()'這個模式,它應該工作: –

回答

0

這是我拿的是對兩個例子線相匹配,與分組

(^[0-9]+[^0-9]+) // capture the intro: 59World or 59Hello Axis Only 
[\\s] //space 
([^\\s]+) // the 5454 or 581 
(?:[\\s]*([0-9]*)) // the optiona 1233 
[\\s] //space 
([^\\s]+) // the 0.00% 
[\\s] //space 
([^s]+) // the R12, ... 
[\\s] //space 
([^\\s]+) //the 58R0.00 
[\\s] //space 
(R[\\d.]+) // concluding R 
$ // end of string 

線路1:

0:[0.92] 59Hello軸只有5454XXX6334 1233333 0.00%R596.11 R12,180.12 R210.880.00%321 58R0.00 R0.00
1:[0,18] 59Hello軸只有
2:[19,30] 5454XXX6334
3:[ 31,38] 1233333
4:[39,51] 0.00%R596.11
5:[52,78] R12,180.12 R210.880.00%321
6:[79,86] 58R0.00
7:[87, 92] R0.00

第2行:

0:[0,75] 59World 58123612344501 0.00%R389.06 R9,337.52 R161.840.00%242 58R0.00 R0.00
1:[0,7] 59世界
2:[8,22] 58123612344501
3:[22,22]
4:[23,35] 0.00%R389.06
5:[36,61] R9,337.52 R161.840.00%242
6:[62,69] 58R0。 00
7:[70,75] R0.00