简体   繁体   English

使用javascript从字符串中获取特定值

[英]get particular value from a string using javascript

using javascript how can i get 0e783d248f0e27408d3a6c043f44f337c54235ce from below string 使用javascript如何从字符串下面获取0e783d248f0e27408d3a6c043f44f337c54235ce

my console.log(stdout); 我的console.log(stdout); prints 版画

 status.html:commit 0e783d248f0e27408d3a6c043f44f337c54235ce

The value 0e783d248f0e27408d3a6c043f44f337c54235ce will be changing. 0e783d248f0e27408d3a6c043f44f337c54235ce将会更改。

Am trying to find that key 我正在寻找那个钥匙

You can use split function: 您可以使用split功能:

stdout.split("status.html:commit ")[1]

Or match : match

stdout.match("status.html:commit (.*)").pop()

You can use . 您可以使用 。 pop() function. pop()函数。

var str = "status.html:commit 0e783d248f0e27408d3a6c043f44f337c54235ce";
str.split("commit").pop().trim()

If commit is a constant, and you just need the rest of the string from commit to the end, you can split the string on commit and pop of the last part 如果commit是一个常量,并且只需要从commit到结尾的其余字符串,则可以在commit和最后一部分弹出时拆分字符串

string.split('commit').pop();

It will leave an extra space, but you can either trim that off, or just add a space in 它将留下一个额外的空间,但是您可以修剪掉它,或者只是在其中添加一个空间

split('commit ')
//           ^ space

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM