[英]Regular Expression for atleast one character and one number with no repeat more than two
[英]Regular expression to check any character in more than two times
我正在尋找一個簡單的正則表達式來匹配字符串中的相同字符兩次以上,就像在 java 腳本中一樣。 (數字1是三倍)112561
您可以檢查一個組在數組中是否超過兩次。
console.log(/(.).*\1.*\1/.test('12561')); console.log(/(.).*\1.*\1/.test('112561'));
以下正則表達式可用於此目的:
.*(.).*\1.*\1.*
這將檢查一個字符是否在字符串中重復超過 2 次。 請注意,這也不使用*
,這是 JavaScript 中性能問題的原因。
console.log(/.+?(.)((?:.)+?\1){1,}/.test('abcZdefZghiZ')) console.log(/.+?(.)((?:.)+?\1){1,}/.test('112561')) console.log(/.+?(.)((?:.)+?\1){1,}/.test('12561'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.