-1

i have the following regex

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

// code to match where get(i) = the string . it doesnt need to match the whole thing just (59Hello Axis Only 5454XXX6334 1233333 ) and (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));
                                }

To match the following

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

It should match both of these lines. ANy help and improving the regex would help

Tinus Jackson
  • 3,397
  • 2
  • 25
  • 58

1 Answers1

0

Here is my take that matches against the two example lines, with groupings

(^[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

Line 1:

0: [0,92] 59Hello Axis Only 5454XXX6334 1233333 0.00%R596.11 R12,180.12 R210.880.00%321 58R0.00 R0.00
1: [0,18] 59Hello Axis Only
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

Line 2:

0: [0,75] 59World 58123612344501 0.00%R389.06 R9,337.52 R161.840.00%242 58R0.00 R0.00
1: [0,7] 59World
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

KevinO
  • 4,303
  • 4
  • 27
  • 36