Why do we often forget to use regular expressions?

Source: Internet
Author: User
There is such a strange phenomenon that designers often forget to use a very amazing invention: regular expressions. They would rather implement very complex string processing logic on their own, and turn dizzy in a bunch of IF and Else, feeling helpless in the face of changing needs.

Today, an error occurs in the system. When determining the type of a phone number, the system mistakenly regards the number starting with 0133 as the number of China Telecom. After some searching, I think the error may beProgram. Opening the program configuration defines a variety of functions, opening and closing range tags, number terminals, more complex. Finally, an error occurred in the interpreter of this configuration. There is a project in the configuration: The number starting with 01 belongs to China Telecom. This configuration is located in front of 0133, and the program does not use the longest match, but uses the fastest match, leading to errors. The error is very simple, but it is relatively concealed. The developer has been searching for it for half a day.

What's more troublesome is that this error cannot be changed now. The system has been running for a long time, and the sequence number of the configuration item cannot be changed. To add a configuration item, evaluate the impact. It is also troublesome to change the program.

In many places in the system, such judgments are made to determine the start, end, length, and interval of a string ...... All use the IF-else judgment. With new services, the existing configuration rules may not be supported, and it may be difficult to modify them.

Why not use a regular expression? The Judgment Rules are greatly simplified, the program logic is simple, and the configuration is strong. It is completely data-driven and easier to test. In case of an error, modify the expression. Demand changes are not afraid. What strings cannot be expressed using regular expressions?

In what situations can I use a regular expression: check the validity of the input box, explain the command line, replace the string, and define the IP address range ......

You should write the word "Regular Expression" on the paper and paste it on the wall. Remind yourself not to forget to use such a great invention during design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.