简体   繁体   中英

Split dot or comma in javascript

How I can write dot or comma in this code:

var mytext = text.split('.');

I want to say split (dot or comma), I don't know how I can write "or" between dot and comma.

You could take a regular expression which looks for dot or comma.

 var text = 'foo,bar.baz', array = text.split(/[.,]/); console.log(array); 

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