Look for a "combination of numbers and letters and spaces" in an input string, noting that the three appear at the same time, or that only numbers and letters appear without spaces.
For example, input "HG 437 djj third dufwf745, DFN^894DK Big Brother-in-law iphone 6s&&&&74854"
Output:
HG 437 DJJ
dufwf745
894dk
IPhone 6s
The following code can be implemented
1String s = "Hg 437 djj third dufwf745, DFN^894DK Big Brother-in-law iphone 6s&&&&74854";2String pattern = "([a-za-z]+\\s+[0-9]+[a-za-z0-9\\s]*|[ a-za-z]+[0-9]+[a-za-z0-9\\s]*| [0-9]+[a-za-z]+[a-za-z0-9\\s]*| [0-9]+\\s+[a-za-z]+[a-za-z0-9\\s]*] [^a-za-z0-9\\s]*];3Pattern r =Pattern.compile (Pattern);4Matcher m =R.matcher (s);5 6arraylist< String > P =NewArraylist<string>();7 while(M.find ()) {8P.add (M.group (1) );9 } Ten One for(String e:p) ASystem.out.println (e);
Java regular matches numbers and letters, and a combination of spaces