The regular expression of Lex and yacc Learning (v)

Source: Internet
Author: User

Regular expression syntax

The lex pattern is an extended version of the regular expression used by the editing programs and utilities. Regular expressions consist of regular characters (representing themselves) and metacharacters (which have special meanings in a pattern).

Metacharacters.

. Matches any single character except for the line break \ n

[]

[] matches any one of the characters in parentheses. Use "-" (dash) to indicate the range of characters, for example [0-9] refers to any of the 10 numbers. If the first character after the opening parenthesis is a dash or close parenthesis, it cannot be interpreted as a meta character. If the first character is the caron "^", then its meaning is changed to match any character other than the one in parentheses. In addition to the C escape sequence that begins with "\", other metacharacters have no special meaning in square brackets.

*

* Matches 0 or more occurrences of the preceding regular expression.

+

+ matches one or more occurrences of the preceding regular expression.

?

? Matches 0 or one occurrence of the preceding regular expression. For example:-? [0-9]+ refers to a number with an optional leading or unary minus sign

{}

{} means different depending on the inside of the parentheses. A single number {n} means that the preceding pattern repeats n times. For example, [A-z]{3} represents any 3 uppercase letters.

If the curly braces contain two numbers separated by commas {n,m}, then they are the minimum and maximum number of repetitions of the preceding pattern. For example: a{1,3} indicates that the letter A appears 1 times to 3 times.

If the second number is lost, it means infinity, so {1,} means +; {0} means *.

If the curly brace contains a name, it indicates that it is replaced with that name.

\

\ Escape Symbol, if the following character is a lowercase letter, then it is the C escape sequence. such as tab stops: \ t

Some implementations allow octal and hexadecimal characters, such as "\123" and "\x3f", to be used in this form.

Otherwise, "\" references the following character, so \* matches an * number.

()

() groups a series of regular expressions.  Each of the * + {} acts directly on its left side of the expression, and | It usually affects both the left and right side of the content. Parentheses can change this situation,

For example: (AB|CD)? EF matches abef or cdef or just EF

|

| Matches the previous or subsequent expression.

“...”

“...” Each character in quotation marks is matched verbatim. A meta character that differs from "\" loses its meaning.

For example: "/*" matches two characters/*

/

/matches the preceding expression only if there is a subsequent expression followed.

For example: 0/1 matches 0 of String 01 but does not match any character in string 0 or 02.

Each mode is allowed only one/and the mode cannot contain both/and $

^

^ as the first character of a regular expression, it matches the beginning of the line, and it is also used in square brackets for negation.

$

$ as the last character of the regular expression, which matches the end of the line

<>

<> one or a list of names within the angle brackets at the beginning of the pattern, so that the pattern applies only to the specified starting state.

"EOF"

EOF is used only in flex, and this particular pattern matches the end of the file.


The regular expression of Lex and yacc Learning (v)

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.