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
oof...
Dont use regexes lmao
is there another way i can check to see in javascript if a string goes by the format [number,number]?
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.
that exact string? couldnt you just compare the strings?
Or do you mean
[343, 3434]
?what is the expected output, and what is your output?
its supposed to return true
but im getting false when i run test using that regex
with [-79.3496,43.7955]
So you want to make sure [] contains numbers?
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
yes, you need to escape the square brackets to make them part of the regex
Didn’t I do that by using [ ?
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 Tyty