java - Is it possible to replace leading zeroes in a string with an equal number of spaces using replaceAll()? -


in java, i'm trying replace strings "001.234" "spacespace1.234". however, i'm regex noob , seem ending leading zeroes replaced single space.

i understand can loop i'm trying pick regular expressions , appreciate :)

no problem:

string resultstring = subjectstring.replaceall("\\g0", " "); 

\g acts \a (the start-of-string anchor) on first iteration of replaceall(), on subsequent passes anchors match spot previous match ended. prevents matching zeroes anywhere else in string, after decimal point.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -