Reputation: 25
I'm having a problem unraveling some Java code sent me. How is this regular expression splitting out the strings with the array?
String[] words = haystack.split("[ \"\'\t\n\b\f\r]", 0);
Upvotes: 0
Views: 758
Reputation: 8938
It is splitting on any of the following in the character class denoted by the opening [
and closing ]
:
– space\"
– quote\'
– apostrophe\t
– tab\n
– line feed\b
– backspace\f
– form feed\r
– carriage returnSee the Java regex reference for clarification about regex character classes and characters.
Also, note that \'
could very well be '
, escaping being unnecessary in that case. Check out an example split on Ideone with this little change.
Upvotes: 2
Reputation: 1
I think you mean haystring (which is a string) is split into an array of strings. All white space characters are used as a delimeter.
Upvotes: 0