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});
  }
上一篇:正则表达式re模块


下一篇:apache nginx日志文件分析