The regex used is /0{6}\b/g
. Note that $
is not used to check the end of the string, but a word boundary character \b
is used which makes this work in a wider range of cases in which other suggestions would fail.
You can very easily derive a similar one yourself for K
, leaving that as an exercise for you :)
After you have done that, you can check if your data matches the first regex or not, and replace if it does. If it doesn't, then test for the second regex (for K) and replace if found.
P.S. The service I used to post the solution (Regex 101) is a very useful service and is a perfect tool for prototyping and learning regex.
http://jsh.zirak.me/2klw //see this only if you still can't figure out how to do it.
This spoiler contains the solution if you can't figure out how to do it