Last active
January 17, 2023 22:16
-
-
Save stefanocudini/d8d95133551ea4158e3bc5b8a6a77075 to your computer and use it in GitHub Desktop.
regexpression test stringified array of locations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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