简体   繁体   中英

Regular expression for prefixed words

I am trying to find all word that are starting with bo or Bo or bO. How can I do this? This is my code:

     var name="Bob bOb ";
     var re=/Bo.*/;
     if (re.test(name))
     document.write("FOUND");
     else 
     document.write("NOT FOUND");

你应该让你的正则表达式不区分大小写,就像这样re=/Bo.*/i

Try this simply approach

 var name="Bob bOb "; var results = name.split( /\\s/ ).filter( function( item ){ return item.toLowerCase().indexOf( "bo" ) == 0 } ); console.log( results );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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