首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >股票和密码市场上的股票行情指标

股票和密码市场上的股票行情指标
EN

Stack Overflow用户
提问于 2022-08-25 06:59:20
回答 1查看 54关注 0票数 0

我很难用以下标准创建一个功能regex:

  • 只在“$”符号后面和句子末尾的空格或之前(空字符串或peroid‘.“)识别最多5个小写字符。
  • 并匹配最多5个大写字母或前面没有“$”号的OR,后面必须跟着空格、符号(逗号、感叹号)或句子末尾(空字符串或peroid‘.)
  • 如果有任何匹配的话

匹配实例

“$APPL落在了TSLA身上。”(应该匹配$APPL和TSLA) "$gme是一个类人猿游戏“(只应该匹配$gme)”这是一个$money的游戏。在哪里兰博“(应该匹配$money和LAMBO)

我一直在玩下面的游戏,让一些角色开始工作,但从来没有一蹴而就:

代码语言:javascript
复制
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));
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-25 07:17:01

这对你有用吗?

代码语言:javascript
复制
\$[a-z]{2,5}\b|\$?\b[A-Z]{2,5}\b

RegEx演示

RegEx解释:

  • \$[a-z]{2,5}\b:第一个小写字母大写
  • |:或
  • \$?\b[A-Z]{2,5}\b:第二个大写字母大写字母
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73483169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档