0

I am using the following pattern below to split the string and based on the pattern save token to an array

String[] s1=s.trim().split("[ !,?._'@]+");
Suryakant Bharti
  • 673
  • 1
  • 6
  • 24
Amit
  • 44
  • 6
  • You can take a look here [Regular Expression Java](https://www.vogella.com/tutorials/JavaRegularExpressions/article.html) You will find your answer here. – Nayan Sarder Feb 07 '20 at 18:03
  • Do you know about this Web site: https://regex101.com/ – Abra Feb 07 '20 at 18:49

1 Answers1

1

Regex Explaination:

[] Match any character in the set inside this.

Match a SPACE or ! or , or ? or . or _ or ' or @ character.

+ Match 1 or more (as many times as they appear) of the preceding token.


So, your code will divide the string s from at every occurance of these characters " !,?._'@" and put it into string array s1.

Suryakant Bharti
  • 673
  • 1
  • 6
  • 24