javascript - How to remove all hidden characters except colons, numbers and 'AM' or 'PM' -


i have string has time in this

"6:00:00 am" or "10:15:00 pm"

i know string has hidden characters in use regex replace characters except colons, numbers , or pm.

not sure if below works because have string comparison check still failing.

selectedtime = selectedtime.replace(/^\w:\s/g, ""); 

i tried

selectedtime = selectedtime.replace(/[^\w:\s]/g, ""); 

as stated... replaced except numbers (the ^\d part), colon (the ^: part) , am/pm (the ^amp part).

selectedtime = selectedtime.replace(/[^\d:amp]/g,"");

you might test using https://regex101.com


Popular posts from this blog