gpt4 book ai didi

javascript - 正则表达式:匹配字符串中不包含下划线的所有单词

转载 作者:行者123 更新时间:2023-12-04 07:43:06 28 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Choosing just the alphanumeric words with regex

(5 个回答)



Regex to extract ONLY alphanumeric words

(3 个回答)


4 个月前关闭。




我的输入是例如 "ghj, klj! ab-CDE-fg_hi" .
当我使用 \w+我得到的模式 ["ghk", "klj", "ab", "CDE", "fg_hi"] .
我需要得到这个数组 ["ghk", "klj", "ab", "CDE"] .
我怎样才能得到想要的输出?

最佳答案

您正在寻找单词边界和字符类:

\b[a-zA-Z]+\b
a demo on regex101.com .

关于javascript - 正则表达式:匹配字符串中不包含下划线的所有单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67348600/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com