0

Need to extract one key from a string containing HTML doc using JavaScript /NodeJs.

I am getting a HTML Page as response of one service which includes a key, which need to be extracted, the key is inside a tag and the page is heavily nested , even after converting to JSON also didn't help.

Tried with regular expression that also not fetching all results (since there are many matches with tag).

The key in tag is like the following:

<script>
$function(){
//some codes
app.init({
//some code
access : {"AccessKey": "dwdfsfcnoidxjbvukv"}

});

//some code
</script>
2
  • That questions smells like a hacking attempt. Can you clarify your intentions please ? Commented Apr 5, 2018 at 17:21
  • 1
    I don't see anything here that looks like NodeJs code. I also see nothing here that does... anything. Mind showing what you have actually tried? Commented Apr 5, 2018 at 17:30

1 Answer 1

1

Use this regex /\{"AccessKey":(.*)\}/ which I think suitable for this problem.

 var data = `<script>
    $function(){
    app.init({
    access : {"AccessKey": "dwdfsfcnoidxjbvukv"}
    });
    </script>`;

    var result = data.match(/\{"AccessKey":(.*)\}/);

    console.log(result[1]);
Sign up to request clarification or add additional context in comments.

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.