正则的预查

news/2024/7/10 23:58:42 标签: javascript, 前端, es6

在这里插入图片描述

javascript">const res=/ES(?=2015|2016)/
console.log(res.exec('ES2015'));
console.log(res.exec('ES2016'));
console.log(res.exec('ES2017'));

在这里插入图片描述

javascript">const res=/ES(?!2015|2016)/
console.log(res.exec('ES2015'));
console.log(res.exec('ES2016'));
console.log(res.exec('ES2017'));

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

javascript">const res=/(?<=2015|2016)E/
console.log(res.exec('2015ES'));
console.log(res.exec('2016ES'));
console.log(res.exec('2017ES'));

在这里插入图片描述
在这里插入图片描述


http://www.niftyadmin.cn/n/1371636.html

相关文章

LeetCode-79. 单词搜索

单词搜索 难度&#xff1a;中等 给定一个 m x n 二维字符网格 board 和一个字符串单词 word 。如果 word 存在于网格中&#xff0c;返回 true &#xff1b;否则&#xff0c;返回 false 。 单词必须按照字母顺序&#xff0c;通过相邻的单元格内的字母构成&#xff0c;其中“相…

LeetCode-27. 移除元素

LeetCode-27. 移除元素 难度&#xff1a;简单 给你一个数组 nums 和一个值 val&#xff0c;你需要 原地 移除所有数值等于 val 的元素&#xff0c;并返回移除后数组的新长度。 不要使用额外的数组空间&#xff0c;你必须仅使用 O(1) 额外空间并 原地 修改输入数组。 元素的顺…

正则小练习

在这里插入图片描述

LeetCode-977. 有序数组的平方

LeetCode-977. 有序数组的平方 难度&#xff1a;简单 给你一个按 非递减顺序 排序的整数数组 nums&#xff0c;返回 每个数字的平方 组成的新数组&#xff0c;要求也按 非递减顺序 排序。 /* 数组其实是有序的&#xff0c; 只不过负数平方之后可能成为最大数了。那么数组平方…

正则常用的标识符

不管什么都是影响捕获的位置的 只能第一位开始捕获&#xff0c;而且必须是连着的

LeetCode-209. 长度最小的子数组

LeetCode-209. 长度最小的子数组 难度&#xff1a;中等 给定一个含有 n 个正整数的数组和一个正整数 target 。 找出该数组中满足其和 ≥ target 的长度最小的 连续子数组 [numsl, numsl1, …, numsr-1, numsr] &#xff0c;并返回其长度。如果不存在符合条件的子数组&#x…

正则的两种创建方法

第二种方法 const res1/\d\w/ console.log(res1); const resnew RegExp("\\s\\d\\w") console.log(res);