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?

M--
  • 25,431
  • 8
  • 61
  • 93
Saranya Garimella
  • 465
  • 1
  • 5
  • 12

2 Answers2

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.

Emma
  • 27,428
  • 11
  • 44
  • 69
  • 1
    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(..,..) – Saranya Garimella Apr 25 '19 at 18:39
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"
Darrin Cullop
  • 1,170
  • 8
  • 14