


How to use regular expressions to match IP addresses and domain names
We know that a complete domain name is composed of root domain, top-level domain, second-level, third-level... domain names, and each level of domain name is separated by dots, and each level of domain name is composed of letters, numbers and minus signs. (The first letter cannot be a minus sign), it is not case sensitive, and the length does not exceed 63.
A single name can be represented by a regularexpression[a-zA-Z0-9][-a-zA-Z0-9]{0,62} To match, the complete domain name includes at least two names (such as google.com, composed of google and com), and there can be a dot representing the root domain at the end (in the specification, the complete domain name is the one with a dot at the end, but It is generally considered that a domain name that includes more than two names is also a complete domain name, even if there is no dot after it).
Regular expression matching the complete domain name:
[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?
An IP string consists of four segments, each segment is a number from 0 to 255, segment Use decimal points to separate segments. For example, 61.139.2.69 is a legal IP string.
If the regular expression is written as \d{1,3}(\.\d{1,3}){3}, it is undoubtedly irresponsible, because it can match 300. Illegal IP strings such as 400.555.666.
To match a number between 0 and 255, there are several matching methods. The following is one of them:
Matching regular expression description
0 ~9 \d Single digit
10~99 [1-9]\d Two-digit number
100~199 1\d\d Three-digit number with hundreds as 1
200~249 2[0 -4]\d Three-digit number, the hundreds place is 2, the tens place is 0~9
250~255 25[0-5] Three-digit number, the hundreds place is 2, the tens place is 5, and the ones place is 0 ~5
Written as a regular expression, that is: (\d|([1-9]\d)|(1\d\d)|(2[0-4]\d)|(25 [0-5])), but when such a regular expression matches a string like 254, it will match 2, 5, and 4 respectively, resulting in 3 matches, which cannot achieve the expected effect. The correct way is to reverse the order as ((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d), because in (xxx|yyy) In this matching behavior, the search is done from left to right.
((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d)(\.((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d)){3}
How to use regular expressions to highlight JavaScript code
Regular expression form verification Example introduction
#How to use regular expressions to match phone numbers, mobile phone numbers and email addresses
The above is the detailed content of How to use regular expressions to match IP addresses and domain names. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Are you wondering where to find or how to change your MAC address on Windows 11, but you don’t know how to do it yet? Since it is possible to hide the IP address, this article will provide simplified steps to set a custom MAC address from the device properties on Windows 11. Can the MAC address be changed? It is possible to change the default MAC address of a Windows computer, but device manufacturers strongly recommend not doing so as it may cause unexpected problems. On the Network Interface Controller (NIC), the MAC address is hardcoded and cannot be changed, but with some drivers this may be possible. In addition, users can also use third-party programs to change the MAC address

Sometimes it is necessary to assign multiple addresses to a single LAN card. For example, if you need to run multiple websites with unique IP addresses or bind applications to different IP addresses, etc. If you are thinking about how to assign multiple addresses to a single network interface card or LAN card, this article will help you achieve it. Follow the steps below till the end and it will be done. So let’s get started! Assign multiple IP addresses to one LAN card Step 1: Use the Windows+R keys together to open the run prompt and type ncpa.cpl, then press the Enter key to open the Network Connection window. Step 2: Right click on your network adapter Ethernet or WiFi option and click Properties. Step 3: From the Properties Window

Address Resolution Protocol (ARP) is used to map MAC addresses to IP addresses. All hosts on the network will have their own IP address, but the network interface card (NIC) will have a MAC address rather than an IP address. ARP is a protocol used to associate IP addresses with MAC addresses. All these entries are collected and placed in the ARP cache. The mapped addresses are stored in cache and they usually do no harm. However, if the entries are incorrect or the ARP cache is corrupt, you may experience connectivity issues, loading issues, or errors. Therefore, you need to clear the ARP cache and fix the error. In this article, we will look at different methods on how to clear ARP cache. method

Any device connected to the Internet has two types of addresses - a physical address and an Internet address. While Internet addresses locate devices globally, physical addresses help identify specific devices connected to a local network. This physical address is technically called a MAC address, and if you're wondering if your iPhone has one, yes, all phones (including iPhones) have their own unique MAC address. What is a MAC address? The Media Access Control or MAC address is a unique indicator used to identify your device from other devices connected to the same network. If you have a device that can connect to the internet, it will register a MAC address. This address is owned by

Why do I need to assign a secondary IP address in Windows 11? Now, we come to the most important question, why do you need to assign a secondary IP address or even multiple in Windows 11? Assuming you have a device with a default IP address and want to use another device, this may require adding a secondary device. Apart from this, it is also used to host various SSL websites. If you have to send a large amount of email in a short period of time, it may be helpful to obtain multiple IP addresses, as there are limits on how much can be sent from one IP address in a specific time frame. Additionally, some users set it up to avoid being blacklisted by spam filters. In addition, add auxiliary

Apple’s official after-sales phone number: Apple’s 24-hour service center phone number: 400-666-8800. The after-sales service telephone number for Apple mobile phones is: 400-666-8800. -627-2273. Apple’s customer service manual service hotline is 400-627-2273 for after-sales support; 400-666-8800 for the online store; and the only official Apple phone number is 400-666-8800. Apple's customer service hotline is 400-666-8800. You can call this number to inquire about hardware, software and third-party accessories of Apple products. It should be noted that Apple’s manual customer service does not provide services 24 hours a day. Their service hours are from 9 a.m. to 9 p.m. (Sundays are from 9 a.m. to 9 p.m.

When it comes to Word, not everything can or needs to be written in plain text. Writing everything down in long descriptive text can really make your Word document boring and confusing. Of course, the comment feature is an option. But even adding comments can make your document look so clunky and heavy. But how do you hover over text that requires a short description and have a little box appear over it with the text you want displayed? Well, this sentence can be called ScreenTip. Once you've inserted a ScreenTip into your document, whenever you want to see the descriptive text you've added, just hover your mouse over the text or line where the ScreenTip was inserted. In this article, we list 2 different methods that you can use to achieve the same purpose. follow

1. Where can I change my Meituan address? Meituan address modification tutorial! Method (1) 1. Enter Meituan My Page and click Settings. 2. Select personal information. 3. Click the shipping address again. 4. Finally, select the address you want to modify, click the pen icon on the right side of the address, and modify it. Method (2) 1. On the homepage of the Meituan app, click Takeout, then click More Functions after entering. 2. In the More interface, click Manage Address. 3. In the My Shipping Address interface, select Edit. 4. Modify them one by one according to your needs, and finally click to save the address.
