Years regex or match everything except years

42 views Asked by At
BMW 1-й серии кузов F20 (2011-)
BMW X1 кузов Е84 2009-
BMW X3 кузов F25 2010-
BMW X5 кузов E70 2006-
BMW X6 кузов E71 2009-
CADILLAC CTS II 2007-
CADILLAC Escalade III 2007- / Chevrolet Tahoe кузов (GMT900) 2007-
CADILLAC SRX II 2010-
Chevrolet Tahoe кузов (GMT900) 2007-

Need regexp to match everything except years

Output:

 BMW 1-й серии кузов F20 
    BMW X1 кузов Е84 
    BMW X3 кузов F25 
    BMW X5 кузов E70 
    BMW X6 кузов E71 
    CADILLAC CTS II 
    CADILLAC Escalade III  / Chevrolet Tahoe кузов 
    CADILLAC SRX II 
    Chevrolet Tahoe кузов

I tried \d{4} or (/ *\([^)]*\) */g, "") or ^[12][0-9]{3}$ - don't work. HElp!

1

There are 1 answers

0
antoni On

If you only need to remove the date that look like "2009-" or "(2009-)", as I expect your output is what you need to keep, then do :

(with 'string' your content)

JS:

var newString= string.replace(/\(?\d{4}-\)?/g, '');

PHP:

$newString= preg_replace('/\(?\d{4}-\)?/g', '', $string);

Hope that helps.