js regex remove everything before certain character (excluding)
JavaScript[Edit]
+
0
-
0
js regex remove everything before certain character (excluding)
1 2 3 4 5 6 7const regex = /^.+(-)/; // match '-' character and everything before it const text = 'Removed part-Example text...'; const result = text.replace(regex, '$1'); // remove everything before '-' character console.log(result); // '-Example text...'
[Edit]
+
0
-
0
js regex remove everything before certain character (excluding)
1 2 3 4 5 6 7 8 9 10 11const regex = /-.*$/; const text = 'Removed part - Example text...'; const match = text.match(regex); if (match) { console.log(match[0]); // '- Example text...' } else { console.log(text); }