Getting started with regular expressions (java)-Introduction

Source: Internet
Author: User

This series will introduce new beginners. The reason for getting started is that it is easy to distinguish regular expressions from various online tutorials, but it is not a matter of 30 minutes. The content is the summary of the accumulated knowledge and the extraction of books: for example, "proficient in regular expressions"-errors are inevitable during the arrangement of the Chinese version of the third edition, which may be a mistake or a mistake ...... The order is 1. basic knowledge 2. basic instance 3. use regular expressions in java 4. matching Principle 5. skills and optimization 6. regexBuddy is a powerful testing tool for regular expressions in android. It can simulate Regular Expressions in multiple languages. It also supports debug Regular Expressions in regular expressions, mainly in the search and replacement of strings. For example, in my current android development, there is always a large number of logs during debugging. If you don't see what the content is, the new log will squeeze out the old log, log contains a lot of content that you don't care about, so I often add grep after adb logcat to ensure that only what I want to see is left. I believe that you must have encountered the following situation during the development process: the content you want to search for is not very sure. For example, if you want to find hate and like, there are not many such strings in the text, and you can easily handle them if they are listed at a time. Therefore, if you do not want to query them twice, you can use regular expressions, you also want to match, so you can also use regular expressions ...... There are many such examples. Let's start with the most basic content. I hope you will be patient. ps: I am very opposed to copying frequently-used regular expressions from the Internet, first, I wrote this for my own needs. For example, the matching phone number is a four-digit, seven-digit phone number, and then the phone number is increased to eight, so your regular expression will not work. This is a good situation. Change {7} to {8}. Even if the program has a problem, you can guess where to modify it. I casually searched the internet for "common regular expressions ", as a result, I found that a person writes [java] ^ [0-9] * [1-9] [0-9] * $ // matches a positive integer. This has many problems. First, it matches the result. is actually a positive integer, however, it may match the type 01, I don't think many people want this. The preceding [0-9] * is totally redundant. Another example is [java] ^ (-\ d +) | (0 + )) $ // match non-positive integers (negative integers + 0). I don't know why this person needs to add so many parentheses. This will only slow down the program speed, at least I can't think of any reason for adding no examples to the two parentheses, I believe that everyone has encountered embarrassment During the replication process. The following is the starting Question: when there is a java example, almost all the following classes will be introduced, and I will not go into details later. [Java] import java. util. regex. Matcher; import java. util. regex. Pattern; import java. util. regex. PatternSyntaxException;

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.