Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add quotes around each word

Tags:

java

regex

I want to transform in Java:

dd fdas dd fdas fads f das fdasf + - || dasf
into:
"dd" "fdas" "dd" "fdas" "fads" "f" "das" "fdasf" + - || "dasf"

basically I want to add quotes around words. \w* -> "\w*\"

like image 531
Gadolin Avatar asked Oct 01 '10 11:10

Gadolin


1 Answers

replaceAll can do this:

String result = input.replaceAll("(\w+)", "\"$1\"");
like image 73
Konrad Rudolph Avatar answered Sep 24 '22 01:09

Konrad Rudolph