I'm trying to split a string by a hyphen and a character but unsure of how to use split with Regex. The string is this:
–u tom –p 12345 –h google.com
The hyphen and character are interchangeable in position and how many of them may appear. I'd like them back in an array. Here is what I have so far:
Scanner reader = new Scanner(System.in);
String entireLine = reader.nextLine();
String[] array = entireLine.split("–", -1);
The result I'd like is:
–u tom
–p 12345
–h google.com
Thanks.