View RSS Feed

Java String

Java String Quantifiers

Rating: 1 votes, 1.00 average.
by , 04-26-2012 at 07:49 PM (853 Views)
Number of occurrences are specified by the quantifiers so that to match. For sake of convenience, Pattern API has been divided into 3 sections with specifications that describe possessive, greedy and reluctant quantifiers are represented below. In first look, this might happen that X?+, X? And X?? Be doing similar things as all of them promise to be match X i.e once, or not at all. Subtle differences of implementations are present that will be discussed at the end of this section.

Name:  1.jpg
Views: 341
Size:  23.1 KB
Java String Quantifiers

Let us start with greedy quantifiers by making 3 varying regular expressions; Letter a which is being followed either by + or ? or *. Now let us observe that what happens when expressions are being tested for i.e. empty input string.

Enter your regex: a?
Enter input string to search:
I found the text "" starting at index 0 and ending at index 0.

Enter your regex: a*
Enter input string to search:
I found the text "" starting at index 0 and ending at index 0.

Enter your regex: a+
Enter input string to search:
No match found.

Submit "Java String Quantifiers" to Facebook Submit "Java String Quantifiers" to Digg Submit "Java String Quantifiers" to del.icio.us Submit "Java String Quantifiers" to StumbleUpon Submit "Java String Quantifiers" to Google

Categories
Regex

Comments