zoukankan      html  css  js  c++  java
  • 正则判断6位数字是递增或递减

    1.正则判断6位数字是递增或递减
    (利用下标 index 值)
    思路一:让每一个项减去下标(即索引) 返回为同一个数字的话(如123456,234567,456789)返回111111,222222。 则为升序
                   让每一个项加上下标(即索引) 返回为同一个数字的话(如987654,876543,654321)返回999999,888888。 则为降序
    思路二:让后一项减去前一项结果为 1 或 -1 则为降序或升序。
     
            //递增
            var str = _num.replace(/d/g, function($0, index) {
                return parseInt($0) - index;
            });
            //递减
            var str2 = _num.replace(/d/g, function($0, index) {
                return parseInt($0) + index;
            });
            if (/^(d)1+$/.test(str)) {
                alert('递增');
                return;
            } else if (/^(d)1+$/.test(str2)) {
                alert('递减');
                return;
            }
     
    2.正则将所有字母转大写

    var s1 = 'ab234cDFGafwer234de111';
    var s2 = s1.replace(/./g, function(w) {
        return w.toUpperCase();
    })
    console.log(s2);
    //AB234CDFGAFWER234DE111
  • 相关阅读:
    Django model 常用方法记录
    程序员的注意事项
    硬件天使的使用
    你是否应该成为一名全栈工程师?
    web技术
    6个处理上面代码异味的重构方法(手法)
    git 命定
    ie console报错
    apache 省略index.php访问
    myisam和innodb的区别
  • 原文地址:https://www.cnblogs.com/yu-709213564/p/6953265.html
Copyright © 2011-2022 走看看