Python代码的模拟操作到JavaScript RE模块
这是代码:
lines = re.split('\\s*\\n+\\s*', text)
joint_stack = []
for line in lines:
words = re.split('\\s+', line)
instruction = words[0]
我的JS代码是:
_parse_hierarchy(text) {
var lines = text.split('\\s*\\n+\\s*');
console.log("Test _parse_hierarchy -> ", lines);
我有数组,但我在一个项目中获得了整个文字。我的数组长度是1。
看起来我需要以行划分的等级...
我也尝试var lines = text.match('\\ s*\\ n+\\ s*');
>没有成功。
有建议吗?
Here is the code :
lines = re.split('\\s*\\n+\\s*', text)
joint_stack = []
for line in lines:
words = re.split('\\s+', line)
instruction = words[0]
My JS code is :
_parse_hierarchy(text) {
var lines = text.split('\\s*\\n+\\s*');
console.log("Test _parse_hierarchy -> ", lines);
I got array but i got whole text in one item. My array length is 1.
Looks like i need regex to split by line...
I also try var lines = text.match('\\s*\\n+\\s*');
with no success.
Any suggestion ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JS格式的正确方法:
\\
=>\
没有
'
或“
)。Correct way for js format:
\\
=>\
and without
'
or"
.