Regular expression keep matched value

Simply use () to quote the value you would like to keep in the result.

String selectedText = "abcdefghi";

selectedText = selectedText.replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)/g, "$1- $2- $3- $4- $5- $6- $7");

// selectedText "a-b-c-d-e-f-g-h-i"

Comments

Popular posts from this blog

CEF Python