Java Regular Expressions (2)

Source: Internet
Author: User
1.5 "no" symbol
The "^" symbol is called the "no" symbol. If it is used in square brackets, "^" indicates the character that you do not want to match. For example, the regular expression in Figure 4 matches all words, except words starting with "X.

Figure 4: match all words except those starting with "X"

1.6 parentheses and white spaces
Assume that you want to extract the month from the birthday date in the format of "June 26,195 1". The regular expression used to match the date can be shown in five:

Figure 5: Date matching all moth DD and YYYY formats

The new "/s" symbol is a blank symbol that matches all blank characters, including TAB characters. If the string matches correctly, how can we extract the month part? You only need to add a parentheses around the month to create a group, and then use Oro API (discussed later in this article) to extract its value. The modified regular expression 6 is shown below:

Figure 6: match all month DD and YYYY dates, and define the month value as the first group.

1.7 other symbols
For simplicity, you can use shortcuts created for common regular expressions. See table 2:
Table 2: common symbols

For example, in the previous example of a Social Security number, we can use "/D" for all the places where "[0-9]" appears ". The modified regular expression 7 is shown below:

Figure 7: Matching all social security numbers in 123-12-1234 format

 

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.