简体   繁体   English

使用 JavaScript RegExp 搜索以特定字母开头的单词

[英]searching for words starting with specific letters using JavaScript RegExp

I need to find all the words in a string array which start with m but not have m in the middle?我需要在字符串数组中找到所有以 m 开头但中间没有 m 的单词?

var arr = "Hello my mother! how is Ramy?";

I tried that:我试过了:

var ragexp = new RegExp("\sm[a-z]*|^m[a-z]*", "g");
var test = regexp.test(arr);  // test should be true if anything matched

i hope this will be useful for you:我希望这对你有用:

\bm[^m]*?\b

在此处输入图像描述

I recommend this page for see more visual the expressions, just select the Flags(global, case insensitive): enter link description here我推荐此页面以查看更直观的表达式,仅 select 标志(全局,不区分大小写):在此处输入链接描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM