Positive-expression Usage guidelines

Source: Internet
Author: User
Tags character classes
1 Overview

A positive expression (regular expression) is an object that describes character patterns, a powerful tool that can be used for pattern matching and substitution, primarily for handling text operations, widely used, and many development languages support positive expressions, such as Java, C #, JavaScript, Perl, and so on.

This document is a guide to the use of positive expressions. Including: basic concepts, development specifications, Java processing methods, JavaScript processing, code examples and so on.

This document enables you to understand the basics of positive expressions, development specifications, common development practices, and the ability to work with a positive expression based on a Java, JavaScript language.

This document is suitable for all Java developers. 2 basic knowledge 2.1 Fundamental Concepts

The regular expression, first proposed by the mathematician Stephen Kleene in 1956, is used in the format of character strings and is later widely used in the field of information and is now one of the standards of ISO (International Standard organization).

A regular expression is a formula that matches a type of string with a pattern. You can compress hours of hard and error-prone text processing work within minutes (or even seconds). Regular expressions are widely supported by various text-editing software, class libraries (such as Rogue Wave tools.h++), scripting Tools (like awk/grep/sed), and interactive Ides like Microsoft's Visual C + + are starting to support it. 2.2 Direct measure characters

Structure

matching

 

 

characters

X

Character x

//

Backslash character

/0n

With octal value 0 character n (0 <= n  <= 7)

/0nn

With octal value 0 of the character nn (0 <= n <= 7)

/0mnn

With octal value 0 Character Mnn (0 <= m <= 3, 0 <= n <= 7)

/xhh

with a hexadecimal value  0x character hh

/uhhhh

Character with hexadecimal value  0x hhhh

/t

Tab ('/u0009 ')

/n

New Line (newline) ('/ u000a ')

/R

Carriage return ('/u000d ')

/F

Page break ('/u000c ')

/a

Alarm (Bell) character ('/u0007 ')

/e The

Escape character ('/u001b ')

/cx

Corresponds to the control character for X

 

In positive expressions, many punctuation marks have special meanings. They are: ^ $. * + ? = ! : | / / () [] {}

The slash character ('/') is used to reference the escaped construct, as defined in the previous table, and to refer to other characters that will be interpreted as non-escaped constructs. Therefore, the expression//matches a single backslash, and/{matches the left parenthesis. 2.3 character classes

Placing individual characters inside square brackets can be grouped into character classes (character Class).

The character class can appear in other character classes, and can contain a set operator (implicit) and an intersection operator (&&). The collection operator represents a class that contains at least one of its operand classes. The intersection operator represents a class that contains all the characters in its two operand classes.

The precedence of the character class operators is as follows, in order from highest to lowest:

1

Literal value escape

/x

2

Group

[...]

3

Range

A-Z

4

and set

[A-E] [I-u]

5

Intersection

[A-z&&[aeiou]]

Note that the different sets of metacharacters are actually inside the character class, not outside of the character class. For example, regular expressions. It loses its special meaning inside the character class, and the expression-becomes the range that forms the meta character.

Character class

[ABC]

A, B, or C (simple Class)

[^ABC]

Any character except A, B, or C (negation)

[A-za-z]

A to Z or A to Z, the letters at both ends are included (range)

[A-d[m-p]]

A to D or M to P:[a-dm-p] (and set)

[A-z&&[def]]

D, E or F (intersection)

[A-Z&&[^BC]]

A to Z, except B and C:[ad-z] (minus)

[A-z&&[^m-p]]

A to Z, not M to P:[a-lq-z] (minus)

Predefined character classes

.

Any character (may or may not match the line terminator)

/d

Number: [0-9]

/d

Non-digit: [^0-9]

/s

White-space characters: [/t/n/x0b/f/r],/t (tab),/n (New Line),/R (return)

/S

Non-whitespace characters: [^/s]

/w

Word characters: [a-za-z_0-9]

/w

Non-word characters: [^/w]

2.4 Repeat

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.