Java Regex to count & delete spaces at beginning of a line?

java, regex

Solution

If you want to count the white spaces at the beginning of a string:

String s = "  123456";
int count = s.indexOf(s.trim());

Problem

Searched other questions couldn't find any results. I've written a regex to delete the spaces from the beginning of the line, but I need to count them and have them at the beginning of the line? ``` scan.nextLine().replaceAll("\\s+", "").trim(); ``` Above is the regex (it's in a while loop). I'm reading in the text in a while loop to check if there is more text and it works fine but I don't know how I can print an integer with the number of spaces removed.

Original source