SQL格式化

formatSql = () => {
    let sqlValue = $("#sql").val();
    let keyword = "select from where and count group by orderby";
    keyword = '(' + keyword.replace(/([+.*|?-([^$])/g, '\$1').replace(/s+/g, '|') + ')';//把匹配关键字中的正则符转义
    let patt = new RegExp(keyword, 'gi');
    let str = sqlValue.replace(patt, function ($, $1) {
      var upr = $1;
      return upr.toUpperCase();
    });
    let formatteSqlValue = sqlFormatter.format(str);
    $("#sql").val(formatteSqlValue);
    this.setState({repsql: formatteSqlValue});
  }
原文地址:https://www.cnblogs.com/zhizhi0810/p/11075821.html