I want to split incoming mail messages into word array. smth like this:
"Hi,.***Build, son,!8loop"
into
['Hi' , 'Build', 'son', 'loop']
i know you want to send me t开发者_运维知识库o learn it by myself but i've read alot of articles but still no ideas.
p.s. using regex+javascript
You can do the following:
Replace all non-word characters by a white space:
str = str.replace(/[\W\d\s]+/g, ' ');
You might have to adjust this to your needs, to replace the right characters:
\W
matches everything expect letters, digits, and underscores\d
matches digits\s
matches white spaces
There are other ways to write an equivalent expression.
Then split bye white space:
words = str.split(' ');
Regular-Expressions.info is a good website to learn about regular expressions. For regular expressions in JavaScript, have a look at the MDC documentation.
精彩评论