---
title: "Split a string with any whitespace chars as delimiters?"  
description: "Split a string with any whitespace chars as delimiters?"  
author: "Anonymous User"  
published: 2015-08-11  
updated: 2015-08-12  
canonical: https://www.mindstick.com/forum/33410/split-a-string-with-any-whitespace-chars-as-delimiters  
category: "java"  
tags: ["java", "string", "split"]  
reading_time: 1 minute  

---

# Split a string with any whitespace chars as delimiters?

What [regex pattern](https://www.mindstick.com/forum/156781/how-to-use-common-message-in-the-regex-pattern-from-the-resource-file-in-asp-dot-net-mvc) would need I to pass to the java.lang.[String](https://www.mindstick.com/articles/1527/string-split-in-c-sharp).[split](https://www.mindstick.com/blog/11920/top-3-voltas-split-acs-for-your-home)() [method](https://www.mindstick.com/forum/166/webservice-method) to split a String into an [Array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) of substrings using all whitespace [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters) (' ', '\t', '\n', etc.) as delimiters?

## Replies

### Reply by Anonymous User

Something in the lines of\

```
myString.split("\\s+");
```

This groups all white spaces as a delimiter.\
So if I have the string:\
"Hello[space][tab]World"\
This should yield the strings "Hello" and "World" and omit the empty space between the [space] and the [tab].\
As VonC pointed out, the backslash should be escaped, because Java would first try to escape the string to a special character, and send that to be parsed. What you want, is the literal "\s", which means, you need to pass "\\s". It can get a bit confusing.\
The \\s is equivalent to [ \\t\\n\\x0B\\f\\r]


---

Original Source: https://www.mindstick.com/forum/33410/split-a-string-with-any-whitespace-chars-as-delimiters

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
