Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.9k points)

I need to split a string base on delimiter - and .. Below are my desired output.

AA.BB-CC-DD.zip ->

AA

BB

CC

DD

zip 

but my following code does not work.

private void getId(String pdfName){

    String[]tokens = pdfName.split("-\\.");

}

1 Answer

0 votes
by (46k points)

I think you need to include the regex OR operator:

String[]tokens = pdfName.split("-|\\.");

What you have will match:

[DASH followed by DOT together] -.

not

[DASH or DOT any of them] - or .

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 12, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer

Browse Categories

...