0

I have a variable rawvalue:

let rawvalue = {abc-def-qwe}

I want to use regex to remove the { and }; I can simply do this by truncating the first and last characters. I built the regex:

^.(.*.).$

I want to know how to apply this regex on my variable to get the desired output?

1
  • Try string.replace(/{([^{}]*)}/g,"\1") Commented Apr 25, 2019 at 18:45

2 Answers 2

0

The syntax you're looking for is like this:

let input = "{abc-def-qwe}";
let re = /^.(.*.).$/;
let fixed = re.exec(input)[1];   // Get the first match group "abc-def-qwe"
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe, this RegEx might be a better choice, which creates one group and you can simply call it using $1 and replace your string:

^\{(.+)\}$

enter image description here

For implementation, you might use, maybe these posts: 1, 2, 3.

1 Comment

Thanks for this, but my question is more focused on how to use the regex in my code? I am not sure of the format as to how to actually format my string using this regex? Something like: var abc = new RegExp(..,..)

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.