Regex to get a parenthesis and the string inside

0

I need to remove a parenthesis with what's inside, example I'm trying to extract this parenthesis:

"Director position."

Reason: I have an old project that has an ajax function that loads a button, which has a js function inside called "define ()", and within the function some parameters go, which are name, job title and etc ... just when it loads the post with some "(a)" function to execute by stating: Uncaught SyntaxError: missing ) after argument list

So I want to use the javascript replace function to remove this

    
asked by anonymous 19.07.2016 / 16:09

2 answers

1

Do this:

var str   = 'cargo diretor (a)';
var regex = /\((.*?)\)/;
str = str.replace(regex, '').trim();

alert(str);

EXAMPLE in jsfiddle

To get only the position (and if before the position is always "charge"):

var str   = 'cargo diretor (a)';
var regex = /\((.*?)\)/;
str = str.replace(regex, '').replace('cargo', '').trim();

alert(str);
    
19.07.2016 / 16:21
0

This should work:

preg_match("/\"(.)*\"/",$input_line,$output_array); 
    
19.07.2016 / 16:14