There is a line of this type "House on Velyaminovskaya (Moscow, (m. Semenovskaya) Veliyaminovskaya St., 27)" "Is it possible to remove the part with js in parentheses that would leave the value" House on Velyaminovskaya "? In regular expressions is not strong.

  • one
    /.+?(?=\h()/ - Edward
  • @Edward, \h in js is not supported. - Qwertiy
  • @ Qwertiy ♦ yes, so I didn’t use it in the answer. - Edward
  • Mark my answer as correct , please, if my decision helped. - Wiktor Stribiżew Nov.

2 answers 2

 var str = 'Дом на Вельяминовской (г. Москва, (м. Семеновская) ул. Вельяминовская, 27)'; var patt = /(.+?)\s?\(.*/g; str = str.replace(patt, '$1'); alert( str ); 

    If you need to remove all nested parentheses, you can use .replace(/\([^()]*\)/g, '') as long as there are no matches left.

    The expression \([^()]*\) finds the character ( , then zero or more characters other than ( and ) ( [^()]* ), and then the character ) .

    JavaScript code:

     var s = "Дом на Вельяминовской (г. Москва, (м. Семеновская) ул. Вельяминовская, 27)"; var pat = /\([^()]*\)/; while (pat.test(s)) { // Пока есть совпадние (пока есть в строке (...)) s = s.replace(pat, ''); // Удали его } console.log(s);