简体   繁体   中英

how to make a regexp in js split to break using special text characters

I need help to make this work in JS: a="casa-me,pois estou farto! Eis a lista:uma;duas;três." a.split(/regex/) to return

a=["casa","me","pois","estou","farto","Eis","a","lista","uma","duas","três"]

Thank you.

干得好:

a.match(/\w+/g).join(' ');

您想要的是一个全局匹配的正则表达式(注意g修饰符):

yourString.replace(/[,;:.!]/g, ' ')

Regexp is something very nice.

var a = 'casa-me,pois estou farto! Eis a lista:uma;duas;três.';

var array = a.match(/[àáâãèéêẽìíîĩòóôõùúûũ\w]+/g);

Each array position will have a word as you want.

Other answers seem to miss things like accented characters, etc. This seems to be working well against your test string, though:

 var re = /[^A-zÀ-ÿ]+/g; var str = 'casa-me,pois estou farto! Eis a lista:uma;duas;três'; var result = str.split(re); alert(result); 

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