Reputation: 305
Is it possible to substring string with regex before first match in Java?
String str = "&¶m1=value 1&¶m1=value&2&¶m1=value & 2¶m2=aaas¶m3=99¶m4=bbb";
I want to have a result like this:
&¶m1=value 1&¶m1=value&2&¶m1=value & 2
Upvotes: 2
Views: 145
Reputation: 12542
If you simply want to split the string with spaces, you can try the following code
String str = "&¶m1=value 1&¶m1=value&2&¶m1=value & 2¶m2=aaas¶m3=99¶m4=bbb";
String[] strAray = str.split(" ");//strArray contains all the splitted tokens
for(String s : strAray){
System.out.println(s);//Prints out each token
}
Upvotes: 0
Reputation: 784958
You can use this regex for matching your test:
^.*?(?=(?<!&)&\w+=)
In Java this regex will be:
"^.*?(?=(?<!&)&\\w+=)"
Upvotes: 1