Java Regex – Examples of Logical Operators ”; Previous Next Following are various examples of Logical Operators using regular expression in java. Sr.No Construct & Matches 1 XY X followed by Y. 2 X|Y Either X or Y. Print
Category: javaregex
Java Regex – Characters
Java Regex – Examples Matching Characters ”; Previous Next Following are various examples of matching characters using regular expression in java. Sr.No Construct & Matches 1 x The character x 2 \ The backslash character 3 n The character with octal value 0n (0 ≤ n ≤ 7) 4 nn The character with octal value 0nn (0 ≤ n ≤ 7) 5 mnn The character with octal value 0mnn (0 ≤ m ≤ 3, 0 ≤ n ≤ 7) 6 xhh The character with hexadecimal value 0xhh 7 uhhhh The character with hexadecimal value 0xhhhh 8 t The tab character (”u0009”) 9 n The newline (line feed) character (”u000A”) 10 r The carriage-return character (”u000D”) 11 f The form-feed character (”u000C”) Print Page Previous Next Advertisements ”;
Java Regex – Useful Resources ”; Previous Next The following resources contain additional information on JAVA. Please use them to get more in-depth knowledge on this topic. Useful Links on Java The JavaTM Tutorials − The Java Tutorials are practical guides for programmers who want to use the Java programming language to create applications. JavaTM 2 SDK, Standard Edition − Official site for JavaTM 2 SDK, Standard Edition Free Java Download − Download Java for your desktop computer now! Sun Developer Network − Sun Microsystem”s official website listing down all the API documentation, latest Java Technologies, Books and other resource. Useful Books on Java To enlist your site on this page, please drop an email to [email protected] Print
Examples of Possessive Quantifiers ”; Previous Next A possessive quantifier is similar to greedy quantifier. It indicates the engine to start by checking the entire string.It is different in the sense if it doesn”t work, if match failed and there is no looking back. Following are various examples of Possessive Quantifiers using regular expression in java. Sr.No Construct & Matches 1 X?+ X, once or not at all. 2 X*+ X, zero or more times 3 X++ X, one or more times. 4 X{n}+ X, exactly n times. 5 X{n,}+ X, at least n times. 6 X{n,m}+ X, at least n but not more than m times Print Page Previous Next Advertisements ”;
Unicode Character Classes
Matching Unicode Character Classes ”; Previous Next Following are various examples of matching Unicode character classes using regular expression in java. Sr.No Construct & Matches 1 p{IsLatin} A Latin script character. 2 p{InGreek} A character in the Greek block. 3 p{Lu} An uppercase letter. 4 p{IsAlphabetic} An alphabetic character (binary property). 5 p{Sc} A currency symbol. 6 P{InGreek} Any character except one in the Greek block. 7 [p{L}&&[^p{Lu}]] Any letter except an uppercase letter. Print Page Previous Next Advertisements ”;
Java Regex – MatchResult Interface ”; Previous Next Introduction The java.util.regex.MatchResult interface represents the result of a match operation. This interface contains query methods used to determine the results of a match against a regular expression. The match boundaries, groups and group boundaries can be seen but not modified through a MatchResult. Interface declaration Following is the declaration for java.util.regex.MatchResult interface − public interface MatchResult Interface methods Sr.No Method & Description 1 int end() Returns the offset after the last character matched. 2 int end(int group) Returns the offset after the last character of the subsequence captured by the given group during this match. 3 String group() Returns the input subsequence matched by the previous match. 4 String group(int group) Returns the input subsequence captured by the given group during the previous match operation. 5 int groupCount() Returns the number of capturing groups in this match result”s pattern. 6 int start() Returns the start index of the match. 7 int start(int group) Returns the start index of the subsequence captured by the given group during this match. Print Page Previous Next Advertisements ”;
POSIX Character Classes
Matching POSIX Character Classes ”; Previous Next Following are various examples of matching POSIX character classes using regular expression in java. Sr.No Construct & Matches 1 p{Lower} A lower-case alphabetic character: [a-z]. 2 p{Upper} An upper-case alphabetic character:[A-Z]. 3 p{ASCII} All ASCII:[x00-x7F]. 4 p{Alpha} An alphabetic character:[p{Lower}p{Upper}]. 5 p{Digit} A decimal digit: [0-9]. 6 p{Alnum} An alphanumeric character:[p{Alpha}p{Digit}]. 7 p{Punct} Punctuation: One of !”#$%&”()*+,-./:;?@[]^_>{|} 8 p{Graph} A visible character: [p{Alnum}p{Punct}]. 9 p{Print} A printable character: [p{Graph}x20]. 10 p{Blank} A space or a tab: [ t]. 11 p{XDigit} A hexadecimal digit: [0-9a-fA-F]. 12 p{Space} A whitespace character: [ tnx0Bfr]. Print Page Previous Next Advertisements ”;
Java Regex – Matching Character Classes ”; Previous Next Following are various examples of matching character classes using regular expression in java. Sr.No Construct & Matches 1 [abc] a, b, or c (simple class). 2 [^abc] Any character except a, b, or c (negation). 3 [a-zA-Z] a through z or A through Z, inclusive (range). 4 [a-d[m-p]] a through d, or m through p: [a-dm-p] (union). 5 [a-z&&[def]] d, e, or f (intersection). 6 [a-z&&[^bc]] a through z, except for b and c: [ad-z] (subtraction) 7 [a-z&&[^m-p]] a through z, and not m through p: [a-lq-z](subtraction). Print Page Previous Next Advertisements ”;
Java Regex – Overview
Java Regex – Overview ”; Previous Next Java provides the java.util.regex package for pattern matching with regular expressions. Java regular expressions are very similar to the Perl programming language and very easy to learn. A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern. They can be used to search, edit, or manipulate text and data. The java.util.regex package primarily consists of the following three classes − Pattern Class − A Pattern object is a compiled representation of a regular expression. The Pattern class provides no public constructors. To create a pattern, you must first invoke one of its public static compile() methods, which will then return a Pattern object. These methods accept a regular expression as the first argument. Matcher Class − A Matcher object is the engine that interprets the pattern and performs match operations against an input string. Like the Pattern class, Matcher defines no public constructors. You obtain a Matcher object by invoking the matcher() method on a Pattern object. PatternSyntaxException − A PatternSyntaxException object is an unchecked exception that indicates a syntax error in a regular expression pattern. Print Page Previous Next Advertisements ”;
Predefined Character Classes
Matching Predefined Character Classes ”; Previous Next Following are various examples of matching predefined character classes using regular expression in java. Sr.No Construct & Matches 1 . Any character (may or may not match line terminators). 2 d A digit: [0-9]. 3 D A non-digit: [^0-9]. 4 s A whitespace character: [ tnx0Bfr] 5 S A non-whitespace character: [^s]. 6 w A word character: [a-zA-Z_0-9]. 7 W A non-word character: [^w] Print Page Previous Next Advertisements ”;