Nicolas Bontempo
Nicolas Bontempo

Reputation: 191

Regex Java Scanner Delimiter

I am trying to read this pattern... What is the Scanner.useDelimiter for this?

This input is:

489 490-1; 491-1; 492-1; 493-1; 494-1; 495-1; 496-1; 497-1; 498-1; 499-1; 500-1;
490 491-1; 492-1; 493-1; 494-1; 495-1; 496-1; 497-1; 498-1; 499-1; 500-1;
491 492-1; 493-1; 494-1; 495-1; 496-1; 497-1; 498-1; 499-1; 500-1;
492 493-1; 494-1; 495-1; 496-1; 497-1; 498-1; 499-1; 500-1;
493 494-1; 495-1; 496-1; 497-1; 498-1; 499-1; 500-1;
494 495-1; 496-1; 497-1; 498-1; 499-1; 500-1;
495 496-1; 497-1; 498-1; 499-1; 500-1;
496 497-1; 498-1; 499-1; 500-1;
497 498-1; 499-1; 500-1;

what I need of output is like:

489

490

1

491

1

492

1

493

1

I tried this delimiter but it didn't work:
Scanner(readerFile).useDelimiter("\\s*-\\s*|;\\s*|\\s*");

Upvotes: 1

Views: 150

Answers (1)

Robby Cornelissen
Robby Cornelissen

Reputation: 97140

The basic idea seems to be to split on anything that is non-numeric, so give this one a try:

Scanner(readerFile).useDelimiter("[^0-9]+");

Upvotes: 3

Related Questions