0

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?

1

1 Answer 1

2

One possible approach:

var lastLine = output.match(/.*$/)[0];

Demo, regex101 playground.

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);    
Sign up to request clarification or add additional context in comments.

6 Comments

am not getting using this
Sorry, what? You don't have the expected result, or you don't understand how it works?
actually that is not working ,-...the output string is the response.but using ur code it is not working i dont know
Where's this string (value of output) taken from? What happens if you just output.match(/not Selected/)[0] instead? And what exactly does 'not working' mean - do you get an error, an empty string, or the whole string in lastLine?
You shouldn't have quotes around your regex. var lastLine = output.match(/.*$/)[0];
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.