我正在尝试从句子中提取最后一个字符串。
var output
是
[info] Sikuli vision engine loaded.
[info] Windows utilities loaded.
[info] VDictProxy loaded.
The arguments are: ['E:/automation.sikuli/automation.py', '{"command":"sel_medi
a","value":"5X7_on_letter"},{"command":"sel_printer","value":"cutepdf"},{"comman
d":"sel_tray","value":"formsource"},{"command":"print","value":"print"}']
5X7_on_letter not Selected
从这里我怎样才能获得最后一个5X7_on_letter not Selected
?
答案 0 :(得分:2)
一种可能的方法:
var lastLine = output.match(/.*$/)[0];
说明:/.*$/
模式匹配除newline
之外的字符串末尾之前的所有符号。这基本上只包括该字符串的最后一行。
一个无正则表达式的替代方法是使用lastIndexOf
来获取最后一个EOL的位置,然后使用其余的字符串。像这样:
var lastLine = output.slice(output.lastIndexOf('\n') + 1);