Replace Characters between ( and )

What I want to do is simple, but acheiving it isn't proving as simple as I wanted.
I am by no means an expert with Javascript, quite the opposite in fact.

I have a string of text (which varies each time it is used), which will be displayed like

(text here) more text here, (text here) more text here ...etc...

The string could have 1 set of "(text here) more text here)" or a number of them, up to 27 maximum.

What I want to do is replace/remove from the string, everything between the "(" and ")", including the "(" and ")", just to leave the "more text here".

Any ideas.

Thanks
LVL 4
Answering4uAntAsked:
Who is Participating?
 
ZylochConnect With a Mentor Commented:
This may need to be tweaked, but please see the following for inspiration.


<html>
<head>
<script type="text/javascript">

var str = "(text here) more text here, (text here) more text here";
var newstr = str.replace(/\(.*?\)\s*/g, "");
alert(newstr);

</script>
</head>
<body>
</body>
</html>

Open in new window

0
 
leakim971PluritechnicianCommented:
Hello Answering4uAnt,

A solution without regex :


<html>
<head>
<script type="text/javascript">

var str = "(text here) more text here, (text here) more text here";
var newstr = str.substr( str.indexOf("(") + 1, str.lastIndexOf(")")-1 );
alert(newstr);

</script>
</head>
<body>
</body>
</html>

Open in new window

0
 
RajeshpolaCommented:
http://tecfa.unige.ch/guides/js/ex-intro/angus_strings.html please use this site, u can write the Reg EXP for the above requirement.
0
 
Answering4uAntAuthor Commented:
perfect
0
All Courses

From novice to tech pro — start learning today.