开发者

Regex to match comma followed by whitespace?

I am trying to make a ruby regex t开发者_StackOverflow中文版o match tags in the format Toys, Cars, Some Other Topic but I can't figure out how to make it so that it splits it at after a comma and white space after but not if there is whitespace in a tag

This is what I have come up with http://rubular.com/r/ptjeQ1KyoD but is wrong for now.

/[\/,$\(\s+)]/


You can just use /,\s*/ (which is much simpler than what you've got!):

'Toys, Cars, Some Other Topic'.split /,\s*/
=> ["Toys", "Cars", "Some Other Topic"]


You should just use:

,\s+

This matches all commas followed by one or more whitespace characters, and doesn't match the spaces beyond Some.


You could use (/,/x) which split all strings with comma(,)

Check here

http://rubular.com/r/8XdjgLK19g

'Toys, Cars, Some Other Topic'.split(/,/x)
=> ["Toys", "Cars", "Some Other Topic"]


function Validate(txt) { txt.value = txt.value.replace(/[^, a-zA-Z]+/g, ''); }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜