我需要一個正則運算式來匹配 javascript 中的某種字串格式,
主題標簽符號'#'必須是第一個和最后一個字符,這兩個字符之間必須有字串,
如果字串不止一個,則'##'每個字串之間必須有兩個主題標簽符號,字串數量沒有限制。
前任。
#string1##string2##string3##...##string4#
#字串1#
#字串##字串2#
我感謝任何幫助和幫助。
uj5u.com熱心網友回復:
您可以使用此模式檢查以下正則運算式
#[^\#] #: 之間的所有字符(除了#)##
(#[^\#] #) :至少有一個字串與模式匹配
^and $: 正則運算式的開始和結束
const checkRegex = (value) => {
const regex = /^(#[^\#] #) $/
return regex.test(value)
}
console.log(checkRegex("#test")) //false
console.log(checkRegex("#test#")) //true
console.log(checkRegex("#test##")) //false
console.log(checkRegex("#test##test#")) //true
console.log(checkRegex("#test##test##")) //false
.as-console-wrapper { max-height: 100% !important; top: 0; }
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/458796.html
標籤:javascript 正则表达式
上一篇:BigQuery的RegexPositiveLookbehind替代方案
下一篇:組合否定字符和捕獲組
