Regular Expressions 101

Community Patterns

Last Occurrence of comma(,) in a string

1

Regular Expression
ECMAScript (JavaScript)

/
\,(?=[^,]*$)
/
g

Description

Used this to dynamically create placeholder text when a user changed the coordinates format from default to custom. ex ['DD', 'DDM', 'DMS'] to remove the comma from the string. The format comes from an array of strings so I had to do a join(', ').replace(/,(?=[^,]*$)/g, ' or') to get DD, DDM or DMS

Submitted by anonymous - 4 years ago