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.
2 answers
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); |
\hin js is not supported. - Qwertiy ♦