I tried
puts [regexp "(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})" 192.168.1.10]
answer is 1.
But if I use
puts [regexp "(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})" 192.168.1.10]
(replaced \[0-9] with \d) answer is 0.
Can someone please tell me why?
You should either escape the backslash in the \d as \\d when used with double quotes.
puts [regexp "(\\d{1,3})\.(\\d{1,3})\.(\\d{1,3})\.(\\d{1,3})" 192.168.1.10]
Or you have to use braces.
puts [regexp {(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})} 192.168.1.10]
Note : With braces, variable substitution won't happen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With