'How to split a String delimited by space in groovy

I am trying to separate my String using spaces and extract the second text of the String value.

Here is my code -

String title = 'testing abcdefgh.abc.cde.fgh test testing issue'
String[] test = title.split(" ");
String[] newTest = test[1];
println newTest

Here is the output i am getting - [a, b, c, d, ., a, b, c, ., c, d, e, ., f, g, h]

NOw the output i am looking for is abcd.abc.cde.fgh, but i am getting [a, b, c, d, ., a, b, c, ., c, d, e, ., f, g, h]

I have used ("\s+"), ("\s"), just a space inside brackets, single and double quotes enclosing a space, nothing works.



Solution 1:[1]

I think the problem is that in Java you have to escape a backslash in a String literal. So while the pattern you want is \s+, you have to put this in Java as "\\s+"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 xpusostomos