Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

常用正则 #22

Open
geqianqian-shihan opened this issue Feb 25, 2020 · 1 comment
Open

常用正则 #22

geqianqian-shihan opened this issue Feb 25, 2020 · 1 comment

Comments

@geqianqian-shihan
Copy link
Owner

去掉空格

    str = str.replace(/\s*/g,"");    // 去除字符串内所有的空格
    str = str.replace(/^\s*|\s*$/g,"");    // 去除字符串内两头的空格
    str = str.replace(/^\s*/,"");    // 去除字符串内左侧的空格
    str = str.replace(/(\s*$)/g,"");    // 去除字符串内右侧的空格 
@geqianqian-shihan
Copy link
Owner Author

geqianqian-shihan commented May 20, 2020

校验带IP

var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/;

var reg1 = /^((2[0-4][0-9])|(25[0-5])|(1[0-9]{0,2})|([1-9][0-9])|([1-9]))\.(((2[0-4][0-9])|(25[0-5])|(1[0-9]{0,2})|([1-9][0-9])|([0-9]))\.){2}((2[0-4][0-9])|(25[0-5])|(1[0-9]{0,2})|([1-9][0-9])|([1-9]))$/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant