See*_*umi 6 javascript regex split
我在这种格式的日志文件中有多行文本:
topic, this is the message part, with, occasional commas.
Run Code Online (Sandbox Code Playgroud)
如何从第一个逗号中拆分字符串,以便将主题和消息的其余部分放在两个不同的变量中?
我尝试过使用这种分割,但是当消息部分中有更多逗号时它不起作用.
[topic, message] = whole_message.split(",", 2);
Run Code Online (Sandbox Code Playgroud)
Ian*_*Ian 13
使用正则表达式"除了第一个逗号之外的所有内容".所以:
whole_message.match(/([^,]*),(.*)/)
Run Code Online (Sandbox Code Playgroud)
[1]将是主题,[2]将是消息.
| 归档时间: |
|
| 查看次数: |
10750 次 |
| 最近记录: |