Private IP Address Identifier in Regular Expression

后端 未结 10 1290
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 09:14

I\'m wondering if this is the best way to match a string that starts with a private IP address (Perl-style Regex):

(^127\\.0\\.0\\.1)|(^192\\.168)|(^10\\.)|(         


        
10条回答
  •  清歌不尽
    2020-12-01 09:43

    Looks right. Personally, I'd change the first one to:

    ^127\.0 
    

    With this: (^127\.0\.0\.1) you looking for anything that starts with 127.0.0.1 and will miss out on 127.0.0.2*, 127.0.2.*, 127.0.* etc.

提交回复
热议问题