03. august 2006 - 11:18
Der er
9 kommentarer og 1 løsning
Help with a Reg Exp!
Hello! I need to verify that a String looks like: 1111.2222.333.4444 Description. The string must contaion 3 "." and can contain any number between 1-9 between the dots so for eg this would be ok: 1234567890.2.4567890.3 I can't get my Pattern in Java correct so if you guys know how to solve this, that I guess should be simple, please let me know. Best regards Fredrik
Annonceindlæg fra HP
03. august 2006 - 11:52
#2
Hello! I tried it like Pattern p = new Pattern("^\\d+\\.\\d+\\.\\d+\.\\d+$"); And Pattern p = new Pattern("\\d+\\.\\d+\\.\\d+\.\\d+$"); Strangely both seems to work? What does the ^ do? My guess is that the ^ means like ! in java programming, am I wrong? Best regards Fredrik
03. august 2006 - 11:54
#4
^ is an anchor that matches "the start of the line". Without it, you will get false positeves: "something 111.222.33.44" - will match.