How to remove leading whitespaces with regular expression in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String regex = "^\\s+";
          
        String s = "       java php python      ";   
 
        s = s.replaceAll(regex, "");
 
        System.out.println(s);
    }
}
  
 
 
  
/*
run:

java php python      
 
*/

 



answered Jun 28, 2019 by avibootz
edited Jun 28, 2019 by avibootz
...