我很难用以下标准创建一个功能regex:
匹配实例
“$APPL落在了TSLA身上。”(应该匹配$APPL和TSLA) "$gme是一个类人猿游戏“(只应该匹配$gme)”这是一个$money的游戏。在哪里兰博“(应该匹配$money和LAMBO)
我一直在玩下面的游戏,让一些角色开始工作,但从来没有一蹴而就:
const found = [
"this is an APPL",
"this is an APPL.",
"this is an $APPL",
"this is an $appl",
"this is an $appl.",
"this is an $appl and orange.",
"this is an $appl, and orange.",
"this is an $APPL and orange.",
"this is an $APPL, and orange.",
"this is an APPL! and orange."
];
const notFound = [
"this is an appl.",
"this is an $applasdfasdf.",
"this is an APPLLLLLL",
"this is an $APPLLLLLL"
];
const matchTicker = /[$][A-Za-z]{0,5}/;
// Should evaluate to TRUE
console.log("\nFOUND\n");
found.forEach((ticker) => {
console.log(matchTicker.test(ticker));
});
// Should evaluate to FALSE
console.log("\nNOT FOUND\n");
notFound.forEach((ticker) => {
console.log(matchTicker.test(ticker));
});发布于 2022-08-25 07:17:01
这对你有用吗?
\$[a-z]{2,5}\b|\$?\b[A-Z]{2,5}\bRegEx解释:
\$[a-z]{2,5}\b:第一个小写字母大写|:或\$?\b[A-Z]{2,5}\b:第二个大写字母大写字母https://stackoverflow.com/questions/73483169
复制相似问题