Getting started with regular expressions (Java)-Introduction

Source: Internet
Author: User

Getting started with regular expressions (Java)-Introduction

Getting started with regular expressions (Java)-1-getting started
Getting started with regular expressions (Java)-2-Basic instances

Getting started with regular expressions (Java)-3-use of regular expressions in Java

Getting started with regular expressions (Java)-matching principles-1-engine classification and universality principles

Getting started with regular expressions (Java)-matching principle-2-backtracking

 

This series will introduce beginners. The reason for getting started is to distinguish them from various online tutorials.

Regular Expressions are simple, but they won't be done in 30 minutes.

 

The content is a summary of the accumulated knowledge and refinement of books: for example, "proficient in regular expressions"-the third edition of the Chinese version

Errors may occur during the sorting process, either by mistake or by mistake ......

The order is

1. Basic Knowledge

2. Basic instance

3. Regular Expressions in Java

4. Matching Principle

5. Skills and Optimization

6. Regular Expressions in Android

 

The test tool used is regexbuddy.

The tool is powerful and can simulate Regular Expressions in multiple languages. It also supports debugging in regular expressions.

 

 

Regular Expressions are mainly used to search and replace 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 definite.

For example, if you want to find hate and like, there are not many strings in the text. If all strings are listed at a time, you can easily handle them, so you don't want to query twice, so you can use regular expressions. If it is in upper case, you also want to match, then 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 and other content from the Internet. The first person to write this is to write for his own needs at that time, for example, if a matching phone number is a 4-7 phone number, and then the phone number is increased to 8, then 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", so I found that one person wrote the following:

^ [0-9] * [1-9] [0-9] * $ // match a positive integer

 

There are many problems

First, it matches a positive integer, but it may match a type like 01. I don't think so.

The preceding [0-9] * is completely redundant.

 

Another example

^ (-\ D +) | (0 +) $ // match a non-positive integer (negative integer + 0)

I don't know why this person needs to add so many parentheses, which will only slow down the speed of the program. At least I can't think of any reason to add the two parentheses.

 

No, I believe everyone has encountered embarrassment During the replication process.

Start now

When there is a Java example, almost all the following classes should be introduced, and we will not go into details later.

import java.util.regex.Matcher;import java.util.regex.Pattern;import java.util.regex.PatternSyntaxException;

 

Getting started with regular expressions (Java)-Introduction

Getting started with regular expressions (Java)-1-getting started
Getting started with regular expressions (Java)-2-Basic instances

Getting started with regular expressions (Java)-3-use of regular expressions in Java

Getting started with regular expressions (Java)-matching principles-1-engine classification and universality principles

 

To be continued

 

 

 

Repost the following link

My blog address

Http://su1216.iteye.com/

Http://blog.csdn.net/su1216/

Related Article

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.