Java - Write code to add underscore before any non letter in a string using regex

Requirements

Write code to add underscore before any non letter in a string using regex

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s = "book2s.com";
        System.out.println(underscore(s));
    }/*from ww w  .  j a  va  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();
    }
}