What does the regular expression (? i) e mean _ Regular expression

Source: Internet
Author: User


Here to the paragraph search data, size if you want to touch thoroughly or write a few pieces of code yourself try It

The corresponding inline flag expression is (? i), which has four different forms:
1, (? i)
2, (?-I.)
3, (? i:x)
4, (?-i:x)
Not with-is the opening sign, with-is off the mark.




public class Test {
public static void Main (string[] args) {
String str = "book";

System.out.println (Str.matches (regex));
}


We have achieved the same effect, of course it is not the best, because only B in the string is uppercase,
We do not need to match all the characters in a case-insensitive case, we can open the logo with the
The second form immediately shuts it down:
String regex = "(? i) b (? i) ook";

In this case, only B is case-sensitive, and the following (?-i) still have to be case-sensitive. Write like this
May seem very uncomfortable, we can also use the 3rd form to directly specify that some characters are case-insensitive.
String regex = "(? i:b) Ook";

Such an expression is semantically the same as the one above. On the efficiency is definitely better than suddenly open, suddenly shut.

Visible inline flag Expressions are much more powerful than specifying compilation parameters.

Use recommendations: If you can determine the case of certain characters, try to use the identified characters, for the indeterminate can be used
(? i:x) in the manner specified. So when you open a case-insensitive switch, there is a certain effect on the performance of the match.

Think about it: String regex = "(? i) b (?-i:oo) k"; The meaning of this expression.

(? i) indicates that the expression on the right side of the location opens ignoring the case mode (? i) to the right of the expression close ignores case mode

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.