We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Java
- Strings
- Java Regex
- Discussions
Java Regex
Java Regex
+ 0 comments class MyRegex { String pattern = "(((25[0-5])|(2[0-4]\\d)|([0-1]?\\d{1,2}))(\\.|$)){4}"; }
+ 0 comments class MyRegex { static String pattern="^(([01]?[0-9]{0,2})|((2[0-4][0-9])|(25[0-5])))\\.(([01]?[0-9]{0,2})|((2[0-4][0-9])|(25[0-5])))\\.(([01]?[0-9]{0,2})|((2[0-4][0-9])|(25[0-5])))\\.(([01]?[0-9]{0,2})|((2[0-4][0-9])|(25[0-5])))$"; }
+ 0 comments ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ this's generated by ChatGPT, for me I can't come up with such pattern string it works for test cases
+ 0 comments class MyRegex{ static String pattern="^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; }
+ 0 comments // 25[0-5] matches 250-255 // 2[0-4]\d matches 200-249 // [0-1]?\d{1,2} matches 0-199 with or without leading 0s // \.|$ matches period or end-of-line after each of the above number group matches // {4} requres the above (number w/ period | number w/ eol) match exaclty 4 times String pattern = "(((25[0-5])|(2[0-4]\\d)|([0-1]?\\d{1,2}))(\\.|$)){4}";
Load more conversations
Sort 608 Discussions, By:
Please Login in order to post a comment