HarmonyOS matchAll使用示例

HarmonyOS
2024-12-25 08:58:39
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect
test2(){
  let text: string =
    "Please contact us at support@geeksforgeeks.org or at courses@geeksforgeeks.org";
  let emailRegex = /\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}\b/g;
  let emails = text.matchAll(emailRegex);
  for (const match of emails) {
    console.log("Found email address:", match[0]);
  }
}

test3(){
  let descriptions: string[] = [
    "Product 123 (ABC-DEF) is the best!",
    "Buy Product ID 456 now!",
    "This is not a product description.",
  ];
  const idRegex = /\bProduct\s+(\d+)\b|\bID\s+(\w+)\b/g;
  for (const description of descriptions) {
    const matches = description.matchAll(idRegex);
    for (const match of matches) {
      console.log("Product ID:", match[1] || match[2]);
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
分享
微博
QQ
微信
回复
2024-12-25 11:04:51
相关问题
HarmonyOS AVScreenCapture使用示例
870浏览 • 1回复 待解决
HarmonyOS NodeContainer的使用示例
1040浏览 • 1回复 待解决
HarmonyOS 消息通知使用示例demo
1251浏览 • 1回复 待解决
xComponet示例代码不能使用
1836浏览 • 1回复 待解决
HarmonyOS 使用Web组件加载页面示例
1298浏览 • 1回复 待解决
napi 基本使用场景示例
2699浏览 • 1回复 待解决
Aspect工具装饰器的使用示例
2966浏览 • 2回复 待解决
使用正则表达式的示例
1268浏览 • 1回复 待解决
使用华为支付的示例代码吗
2559浏览 • 1回复 待解决
使用华为账号服务登录的示例代码
2784浏览 • 1回复 待解决
使用hiappevent获取崩溃日志的示例代码
2865浏览 • 1回复 待解决
JSVM使用示例,有谁知道吗?
2159浏览 • 1回复 待解决
HarmonyOS 文件拷贝示例
726浏览 • 1回复 待解决
HarmonyOS web交互示例
765浏览 • 1回复 待解决
HarmonyOS List拖动排序示例
1090浏览 • 1回复 待解决
HarmonyOS Toolbar组件示例
826浏览 • 1回复 待解决
HarmonyOS 蓝牙读写示例
718浏览 • 1回复 待解决
HarmonyOS 图片压缩示例
444浏览 • 2回复 待解决