How to use regex in JavaScript

Hello everyone
I have a file name
My Test File Name (1)
I want to get the name in a variable without last space(1)
I want to get the name like
My Test File Name
For this I Use Regex in Standard Function

Clipboard COPYNAMES=nopaths REGEXP (.*)\s \1

How to use this kind of Regex in JavaScript?
Now I have write this code, it's can get the Selected File name in a variable

function OnClick(clickData)
{
var eSel = new Enumerator(clickData.func.sourcetab.selected);


var getfoldername = eSel.item().realpath.filepart;

	DOpus.Output(getfoldername);
	}

by the way my main goal is create a folder from Selected file name but without space(1) or space(99)

Type your exact subject ("how do I use regex in Javascript") into Google and you get back lots of explanations and examples.

This isn't a forum for learning Javascript, and this information is already on the web.

(The random indentation in your Javascript when you post it also suggests you're still copy & pasting things together without understanding them properly. Please go through some Javascript tutorials. It really is worth the time to understand things properly.)

function OnClick(clickData)
{
var eSel = new Enumerator(clickData.func.sourcetab.selected);


var getfoldername = eSel.item().realpath.filepart;

var re = /\s\([0-9]+?\)\.(.*)/;
var regfolder = getfoldername.replace(re, "");

	DOpus.Output(regfolder);
	}

is there any other better way to do that?