SyntaxError: unterminated regular expression literal javascript

I am getting different error’s for this code in javascript in different browsers.

 travelAMPM = time.match(/s(AM|PM)$/i)[1]; 

Firefox error:

SyntaxError: unterminated regular expression literal.

Google Chrome error:

Uncaught SyntaxError: Invalid regular expression: missing /

What is wrong in the code? This code is working fine in jsfiddle and Jsbin, but not in Firefox browser and Google chrome browser ?

Firefox debugger shows the code as: enter image description here


Adding before $ in the code solved my problem.

Working code:

travelAMPM = time.match(/s(AM|PM)$/i)[1]; 

Leave a Reply

Your email address will not be published. Required fields are marked *