excel - Getting "TRUE" when RegEx doesn't match? -
i attempting try , use regular expressions pattern match in vba. i've added reference regular expression libraries , using following code test.
sub testing() dim re dim val set re = new regexp re.pattern = "[0-9]{5}" re.ignorecase = true val = range("a8").value msgbox val msgbox re.test(val) end sub
the issue when i'm testing string formatted as:
1234 565 4444543 12 33
i receiving "true" when use {5} , "false" when using {6}. why this?
shouldn't both {5} , {6} return "false" in case?
if regex matching on whitespace, how prevent this? want match 4 numbers followed 1 space followed 3 numbers, etc.
help!
you need anchor regular expression:
re.pattern = "^[0-9]{5}$"
otherwise matches if finds pattern anywhere in input. ^
matches beginning of input, $
matches end of input.
i'm not sure why [0-9]{6}
returns false
input, since there 6 digits in 4444543
.
Comments
Post a Comment