0

My string is : BETA-GE=a034-56aw-y567-54er; beta=/;

I would like to retrieve the string "a034-56aw-y567-54er" from the above string in nodejs.

The code I have written currently is:

var xs = "BETA-GE=a034-56aw-y567-54er; beta=/;";
var regex = /^BETA-GE=[a-zA-Z0-9-]*[;]*./;
let match = regex.exec(xs);
console.log(match[0]);

The result displays BETA-GE=a034-56aw-y567-54er;

0

2 Answers 2

3

Surround the part you want with a capture group and access it:

var xs = "BETA-GE=a034-56aw-y567-54er; beta=/;";
var regex = /^BETA-GE=([a-zA-Z0-9-]*)[;]*./;
let match = regex.exec(xs);
console.log(match[1]);

Here is the working regex.

Sign up to request clarification or add additional context in comments.

Comments

0

You have just to create a group in your regexp and get the second match :

var xs = "BETA-GE=a034-56aw-y567-54er; beta=/;";
var regex = /^BETA-GE=([a-zA-Z0-9-]*)[;]*./;
let match = regex.exec(xs);
console.log(match[1]);

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.