INTRO
I have a Google App Script Web App which has a form which contains a TextArea, and when submitted saves the data in a Google Sheet.
This text-area collects Employee ID's and will receive input from non-tech savvy users.
The users may use the following formats when entering the ID's into the textarea, including typos such as extra spaces, commas, or a mixture of all 3 formats.
A) Separated by a space.
A123456 B001234 TMP00123456
B) Separated by a comma (with or without a space too)
A123456,B001234, TMP00123456
C) One / line.
A123456
B001234
TMP00123456
THE OBJECTIVE
I need to cleanse the data above before its written to the Google Sheet. The cleansed (expected outcome) data should look like
123456,001234,00123456
THE PROBLEM
I cant seem to get REGEX to work correctly. I have tried many variations.
var agentIds = form.agentIds.replace(/[^\d]+/g, ',').replace(/^,+|,+$/g, '');
In a nutshell, I am looking for regex to...
- Replace all spaces with comma.
- Replace all line-breaks with commas.
- Remove all letters.
- IF there are 2 or more commas next to each other, remove the extras.
II am not sure if this is the most efficient way...but the only way I could think of. I am open to suggestions.
Thanks for your help!!! :)