Seventh Week assignment

Source: Internet
Author: User
Tags character classes

How do I use regular expressions to check strings?

such as: Check whether the string conforms to the mailbox rules;

Checks if the string conforms to a number greater than or equal to zero;

The basic rules for regular expressions are as follows:

Character
X Character x
\\ Backslash character
/ N Characters with octal value 0 n (0 <= n <= 7)
/ nn Character nn with octal value 0 (0 <= n <= 7)
/ Mnn Characters with octal value 0 mnn(0 <= m <= 3, 0 <= n <= 7)
\x hh Character hh with hexadecimal value of 0x
\u HHHH Character with hexadecimal value of 0x hhhh
\ t tab (' \u0009 ')
\ n New lines (line break) (' \u000a ')
\ r Carriage return character (' \u000d ')
\f Page break (' \u000c ')
\a Alarm (Bell) character (' \u0007 ')
\e Escape character (' \u001b ')
\c x The control that corresponds to x
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](set)
[A-z&&[def]] d,e or F(intersection)
[A-Z&&[^BC]] a to Z, except for 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 Terminator)
\d Numbers:[0-9]
\d Non-numeric: [^0-9]
\s whitespace characters:[\t\n\x0b\f\r]
\s Non-whitespace characters:[^\s]
\w Word character:[a-za-z_0-9]
\w Non-word characters:[^\w]
Greedy number of words
X ? X, not once or once
X * X, 0 or more times
X + X, one or more times
X {n} X, exactly n times
X {n,} X, at least n times
X {n,m} X, at least n times, but not more than m Times

Typically, a double slash indicates that the string is a regular expression, while the ^ represents the beginning and $ means the end, such as/^.....$/

Whether the string conforms to the mailbox rule:/^\[email protected]\w+ (\.\w+) +$/

\w as above table: Word characters [a-za-z_0-9], \w+: Represents one or more word characters

Plus @, then one or more, \. '. ' character, so go on

whether a string conforms to a numeric rule greater than or equal to zero: /^ [1-9]\d* (\.\d+)? | 0 (\.\d+)? $/

[1-9]: Indicates that the first number is 1-9

\d: Represents a number, \d*: 0 or more digits behind

(\.\d+)?: Represents the number after the decimal point, as well as one or

|: means "or".

Note that in Java the string needs to be escaped, all requiring two backslashes \ \, as /^ [1-9]\\d* (\\.\\d+)? | 0 (\\.\\d+)? $/

above is use regular expressions to check strings

SELECT

orders.*,

User.username,

User.sex,

User.address

From

Orders

USER

WHERE orders.user_id = user.id

Seventh Week assignment

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.