String and Regular Expression

Source: Internet
Author: User

A string can contain any character from the Unicode Character Set. Common methods and notes for string application:

1. The character string without any character is a null string (""), and the character string indicating space is ("").

2. Common Methods:

From string to array, a string is decomposed into a series of segments, and these segments are put into a string array, split (char [] delimeter, int L ); the first parameter must appear as a char array, and the first element of the array is a character used as a separator.

Programming string from string array: Join Method

Several Methods for comparing strings: s1.equal (string S2): Return bool value; s1.compareto (S2): Return-, 1; string. compare (S1, S2): return value is the same as compareto;

Others include intercepting the substring () of a string, case-insensitive conversion method, and inserting method insert.

Difference between string and stringbuilder: the string class object remains unchanged. Each time a new object is generated to save the value, stringbuilder is variable and the most primitive value is changed. stringbuilder hasChars array attributesThis attribute returns the characters at the specified position in the parameter, and sets the characters to be passed as parameters.

Regular Expression: a regular expression is a string defined for other string search modes. If you want to match, you generally need to use the match class. The match class provides a method to store data that matches regular expressions.

Regular Expressions match words but do not match spaces.

Several common symbols of a regular expression:

Quantifiers:

+: Indicates that the regular expression matches one or more characters that follow the regular expression;

*: Indicates that the regular expression must match zero or multiple characters in the regular expression;

? : Matches zero or one quantizer;

{}:{ N}: Match n times; {n, m}: Match n times, Max. m times. N is the minimum value, and m is the maximum value;

Use character classes (three common ):

Period (.): wildcard;

Square brackets []: Match character groups

Escape Character (^): indicates the inverse of the matching character class or the negative (not) of the character class );

Assertions:

1. Composed of delimiters (^), indicating that regular expressions can only start matching at the beginning of a string or line;

2. It is composed of dollar signs ($), indicating that regular expressions can only start matching at the end of a string or line;

3. "\ B" indicates that matching can only happen at the beginning or end of a word separated by spaces.

Group structure:

Anonymous group and naming Group

Zero-width forward pre-search assertion and zero-width reverse pre-search assertion

Format:

Zero-width forward pre-search assertion: Forward right or reverse right search

Zero-width reverse pre-search assertion: Forward left or reverse left search

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.