1

如何用)or分割 JS 字符串=?我知道我应该使用正则表达式,split()但不知道我应该使用的确切正则表达式。试过这个mystring.split("[\\=\\)]+")但不起作用!

4

2 回答 2

6

In JavaScript, wrapping the regex in quotes won't work. You have to wrap it in slashes:

> 'hello)world=yes'.split(/[=)]+/)
["hello", "world", "yes"]
于 2012-08-26T08:19:22.233 回答
3
result = mystring.split(/[)=]/);

works. You do need to assign the result back to another (or the same) string, though.

于 2012-08-26T08:19:00.703 回答