匹配中文字符:

let reg=/([\u4E00-\u9FFF]+)/; //\u代表Unicode编码

匹配电话号码:

let reg=/^1[34578]\d{9}$/;

给每三位数字添加一个逗号:

let reg=/(?=(\B(\w{3})*)$)/g;
let str='10000000';
str.replace(reg,',');

字符串去重:

let reg=/(\w)\1+/g;
let str='aaabbbcccddd';
console.log(str.replace(reg,'$1')); //只能去掉连续重复的字符

将字符串转换成小驼峰命名:

let reg=/-(\w)/g;
let str='the-first-index';
str.replace(reg,($,$1)=>{
return $1.toUpperCase();
});

匹配正确的IP地址(IPv4地址由4组数字组成,每组数字之间以“.”分隔,每组数字的取值范围是0~255.):

let reg=/^((2[0-4]\d|25[0-5]|1\d{2}|[1-9]?\d)\.){3}(2[0-4]\d|25[0-5]|1\d{2}|[1-9]?\d)$/;
let str='255.36.233.0';
console.log(reg.test(str));//true

持续更新...

【20190405】JavaScript-整理一些常用正则式的更多相关文章

  1. 基于php常用正则表达整理(下)

    61        \n 匹配一个换行符.等价于 \x0a 和 \cJ.62        \r 匹配一个回车符.等价于 \x0d 和 \cM.63        \s 匹配任何空白字符,包括空格.制 ...

  2. PHP 常用正则汇总

     平时做网站经常要用正则表达式,下面是一些讲解和例子,仅供大家参考和修改使用:    }|d{})-((([-]{}))|([|]))-(([-]([-]{}))|([|]))$/   ([-]{}) ...

  3. php常用正则

    平时做网站经常要用正则表达式,下面是一些讲解和例子,仅供大家参考和修改使用: 2.    "^\d+$" //非负整数(正整数 + 0) 3.    "^[0-9]*[1 ...

  4. javascript中字符串常用操作整理

    javascript中字符串常用操作整理 字符串的操作在js中非常频繁,也非常重要.以往看完书之后都能记得非常清楚,但稍微隔一段时间不用,便会忘得差不多,记性不好是硬伤啊...今天就对字符串的一些常用 ...

  5. JavaScript正则式练习

    使用正则式匹配第一个数字和最后一个数字,使用环视 str2 = 09051 : Fast Food Restaurants - Concession Stands/Snack Bars Delicat ...

  6. JavaScript正则式入门

    正则式 正则表达式,又称规则表达式.(英语:Regular Expression,在代码中常简写为regex.regexp或RE),计算机科学的一个概念.正则表通常被用来检索.替换那些符合某个模式(规 ...

  7. Python正则式的基本用法

    Python正则式的基本用法 1.1基本规则 1.2重复 1.2.1最小匹配与精确匹配 1.3前向界定与后向界定 1.4组的基本知识 2.re模块的基本函数 2.1使用compile加速 2.2 ma ...

  8. JavaScript正則表達式知识汇总

    Js 正則表達式知识汇总 正則表達式: 1.什么是RegExp?RegExp是正則表達式的缩写.RegExp 对象用于规定在文本中检索的内容. 2.定义RegExp:var +变量名=new RegE ...

  9. shell 常用正则

    shell常用正则表达式   “^\d+$” //非负整数(正整数 + 0)   “^[0-9]*[1-9][0-9]*$” //正整数   “^((-\d+)|(0+))$” //非正整数(负整数 ...

随机推荐

  1. Java作业 十一(2017-11-13)

    /*关键字*/ package com.baidu.www; abstract class A { private String name; public A(String name) { this. ...

  2. High Availability手册(2): 架构

    最底层是通信层corosync/openais 负责cluster中node之间的通信 上一层是Resource Allocation Layer,包含下面的组件: CRM Cluster Resou ...

  3. [Swift]LeetCode188. 买卖股票的最佳时机 IV | Best Time to Buy and Sell Stock IV

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  4. [Swift]LeetCode345. 反转字符串中的元音字母 | Reverse Vowels of a String

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1: In ...

  5. [Swift]LeetCode829. 连续整数求和 | Consecutive Numbers Sum

    Given a positive integer N, how many ways can we write it as a sum of consecutive positive integers? ...

  6. [Swift]LeetCode862. 和至少为 K 的最短子数组 | Shortest Subarray with Sum at Least K

    Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there ...

  7. 互联网最新kafka技术面试题含答案

    1.Kafka 的设计时什么样的呢? Kafka 将消息以 topic 为单位进行归纳 将向 Kafka topic 发布消息的程序成为 producers. 将预订 topics 并消费消息的程序成 ...

  8. 网络协议 9 - TCP协议(下):聪明反被聪明误

    网络协议 1 - 概述 网络协议 2 - IP 是怎么来,又是怎么没的? 网络协议 3 - 从物理层到 MAC 层 网络协议 4 - 交换机与 VLAN:办公室太复杂,我要回学校 网络协议 5 - I ...

  9. socket编程: TypeError: must be bytes or buffer, not str

    先看一段代码 #!/usr/bin/env python3 from socket import * serverName = "10.10.10.132" serverPort ...

  10. Nancy in .Net Core学习笔记 - 初识Nancy

    前言 去年11月份参加了青岛MVP线下活动,会上老MVP衣明志介绍了Nancy, 一直没有系统的学习一下,最近正好有空,就结合.NET Core学习总结了一下. 注: 本文中大部分内容都是对官网文档的 ...