I'm trying to extract several words from a string with regex matcher &pattern. I did spend some time to make the regular expression I'm using but this doesn't work as expected, any help would be very appreciated.
I made the regular expression I'm using but this doesn't work as expected, some help would be great. I'm able to extract the chars from the words I want but not the entire word.
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main (String[] args){
String mebo = "1323 99BIMCP 1 2 BMWQ-CSPS-D1, 0192, '29229'";
Pattern pattern = Pattern.compile("[((a-zA-Z1-9-0)/W)]");
Matcher matcher = pattern.matcher(mebo);
while (matcher.find()) {
System.out.printf("Word is %s %n",matcher.group(0));
}
}
}
This is current output:
Word is 1 Word is 3 Word is 2 Word is 3 Word is 9 Word is 9 Word is B Word is I Word is M Word is C Word is P Word is 1 Word is 2 Word is B Word is M Word is W Word is Q Word is - Word is C Word is S Word is P Word is S Word is - Word is D Word is 1 Word is 0 Word is 1 Word is 9 Word is 2 Word is 2 Word is 9 Word is 2 Word is 2 Word is 9
============
My expectation is to iterate entire words for example:
String mebo = "1323 99BIMCP 1 2 BMWQ-CSPS-D1, 0192, '29229'"
word is 1323 word is 99BIMCP word is 1 word is 2 word is BMWQ-CSPS-D1 word is 0192 word is 29229
Aucun commentaire:
Enregistrer un commentaire