Reputation: 3920
I am trying to extract last string from a sentence.
var output
is
[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
From this How can I get the last 5X7_on_letter not Selected
only?
Upvotes: 0
Views: 241
Reputation: 106483
One possible approach:
var lastLine = output.match(/.*$/)[0];
Explanation: /.*$/
pattern matches all the symbols preceding the end of the string except newline
ones. This will essentially cover only the last line of that string.
A regex-free alternative is using lastIndexOf
to get the position of the last EOL, then taking the rest of the string. Like this:
var lastLine = output.slice(output.lastIndexOf('\n') + 1);
Upvotes: 2