Skip to content

Instantly share code, notes, and snippets.

@stefanocudini
Last active January 17, 2023 22:16
Show Gist options
  • Save stefanocudini/d8d95133551ea4158e3bc5b8a6a77075 to your computer and use it in GitHub Desktop.
Save stefanocudini/d8d95133551ea4158e3bc5b8a6a77075 to your computer and use it in GitHub Desktop.
regexpression test stringified array of locations
/**
test str is formatted "11.2,46.1|11,46|11.2,46.1|11.1,46.2"
*/
function validLocations(str) {
const regAll = /(?=^([^\|]*\|){3}[^\|]*$)(?=^([^,]*,){4}[^,]*$)/
// contains min 3 pipe and 4 commas
, regPipe = /^([^\|]*\|){3,}[^\|]*$/
// contains min 3 pipe
, regComma = /^([^,]*,){4,}[^,]*$/
// contains min 4 comma
return regAll.test(str)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment