Regex to take a parenthesis and string inside together

Asked

Viewed 92 times

0

need to remove from a string a parenthesis with what is inside, example of which I am trying to extract this parenthesis:

"director position (a)".

reason: I have an old project that has an ajax function that loads a button, that has a js function inside called "define()", and inside the function there are some parameters, which are name, position and etc... just when you load the post with some "(a)" the function stops informing: Uncaught SyntaxError: missing ) after argument list

so I want to use the replace function of javascript to remove this

2 answers

1


Do so:

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

alert(str);

EXAMPLE in jsfiddle

To obtain only the post (and if before the post is always "post"):

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

alert(str);

0

This should work:

preg_match("/\"(.)*\"/",$input_line,$output_array); 
  • Careful Daniel, it’s supposed to be with javascript. Attention to question tags

Browser other questions tagged

You are not signed in. Login or sign up in order to post.