[英]Extract the portions of the string using REGULAR Expression in node.js
[英]Extract last string from a sentence using node.js
我試圖從句子中提取最后一個字符串。
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
?
一種可能的方法:
var lastLine = output.match(/.*$/)[0];
演示 , regex101游樂場 。
說明: /.*$/
pattern匹配除newline
之外的字符串newline
之前的所有符號。 這基本上只涵蓋該字符串的最后一行。
一個無正則表達式的替代方法是使用lastIndexOf
來獲取最后一個EOL的位置,然后使用其余的字符串。 像這樣:
var lastLine = output.slice(output.lastIndexOf('\n') + 1);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.