-1

I have this string $183,361 [10.00 FTE].

I want to trim it to only keep [10.00 FTE]

I have only been able to remove the square brackets with /\[(.*?)\]/.

This is how I am displaying the string on screen

<>
    {rowData.Q1.replace(*Regex*, "")}
</>

What regex expression will help with getting the output I want?

Ciaran Crowley
  • 425
  • 1
  • 4
  • 18

1 Answers1

1

Assuming you are using JavaScript here, I would just use string match() with a capture group:

var input = "$183,361 [10.00 FTE]";
var output = input.match(/\$\d{1,3}(?:,\d{3})*(?:\.\d+)? (\[.*?\])/)[1];
console.log(output);

If you don't insist on the bracketed term being preceded by a dollar amount, then simplify the regex pattern to \[.*?\] and use this version:

var input = "$183,361 [10.00 FTE]";
var output = input.match(/\[.*?\]/)[0];
console.log(output);
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360