Write code to add underscore before any non letter in a string using regex
//package com.book2s; public class Main { public static void main(String[] argv) { String s = "book2s.com"; System.out.println(underscore(s)); }/* w w w . j av a 2 s . c o m*/ public static String underscore(String s) { return s.replaceAll( String.format("%s|%s|%s", "(?<=[A-Z])(?=[A-Z][a-z])", "(?<=[^A-Z])(?=[A-Z])", "(?<=[A-Za-z])(?=[^A-Za-z])"), "_").toLowerCase(); } }