Javascript examples for RegExp:RegExp Match
Delete the last occurrence of the match with replace()
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//ww w . j ava2 s .c o m var str = "[00:28.1] to [00:28.5] [00:28.51] demonstrate\n\ [00:29.1] text"; var str = str.replace(/^([\s\S]*[^\n])(\[\d{1,2}:\d{1,2}\.\d{0,2}\])/, "$1"); console.log(str); } </script> </head> <body> </body> </html>