Why doesn't my Regex match with the given example?

im getting a false value when i test my regex with the given string not sure why
12 Replies
the magic guy
the magic guy3y ago
oof... Dont use regexes lmao
Revan
RevanOP3y ago
is there another way i can check to see in javascript if a string goes by the format [number,number]?
elurbi
elurbi3y ago
try debugging your regex here https://regex101.com/
regex101
regex101: build, test, and debug regex
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.
the magic guy
the magic guy3y ago
that exact string? couldnt you just compare the strings? Or do you mean [343, 3434]?
split
split3y ago
what is the expected output, and what is your output?
Revan
RevanOP3y ago
its supposed to return true but im getting false when i run test using that regex with [-79.3496,43.7955]
the magic guy
the magic guy3y ago
So you want to make sure [] contains numbers?
Revan
RevanOP3y ago
yeah numbers that are seperated with a comma well decimal numbers that can be positive or negative but they can be whole numbers as well it works when i remove the square brackets from regex and when i remove square brackets from my string so i think the square brackets might be the culprit
elurbi
elurbi3y ago
yes, you need to escape the square brackets to make them part of the regex
Revan
RevanOP3y ago
Didn’t I do that by using [ ?
split
split3y ago
the sequence (\.\d)* is wrong you are checking for a dot and a digit repeatedly like .1.0.1.0.1 etc when you should be searching for a dot, THEN a digit repeatedly use \.\d* instead of (\.\d)* heres a short working version
\[-?\d*\.?\d*,-?\d*\.?\d*\]
\[-?\d*\.?\d*,-?\d*\.?\d*\]
Revan
RevanOP3y ago
Tyty
Want results from more Discord servers?
Add your server