0

using javascript how can i get 0e783d248f0e27408d3a6c043f44f337c54235ce from below string

my console.log(stdout); prints

 status.html:commit 0e783d248f0e27408d3a6c043f44f337c54235ce

The value 0e783d248f0e27408d3a6c043f44f337c54235ce will be changing.

Am trying to find that key

2
  • 3
    string.split('commit').pop(); Commented Jun 9, 2014 at 9:06
  • please post as answer so that i can accept your anser Commented Jun 9, 2014 at 9:08

3 Answers 3

1

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

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

Comments

1

You can use split function:

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

Or match:

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

Comments

1

You can use .pop() function.

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

Comments

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.