REGEX / NOTES</>↗Regex03 Nov 2010
Capturing groups are a way to treat multiple characters as a single unit. They are created by placing the characters to be grouped inside a set of parentheses. For example, the regular expression (dog) creates a single group containing the letters d, o and g. Regular expressions can also define other capturing groups that correspond […]
REGEX / NOTES</>↗Regex02 Nov 2010
You can use the | operator (logical OR) to match characters or expression of either the left or right of the | operator. For example the (t|T) will match either t or T from the input string. package org.kodejava.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class LogicalOrRegexDemo { public static void main(String[] args) { // Define […]
REGEX / NOTES</>↗Regex02 Nov 2010
In regex, you also have a number of predefined character classes that provide you with a shorthand notation for commonly used sets of characters. Here are the list: Predefined Class Matches . Any character d Any digit, shorthand for [0-9] D A non digit, [^0-9] s A whitespace character [^s] S Any non whitespace character […]
REGEX / NOTES</>↗Regex02 Nov 2010
If you want to find the occurrence of a pattern in more precise position, for example at the beginning or the end of line, you can use boundary matcher. Boundary matcher are special sequences in a regular expression when you want to match a particular boundary. Here are the list: Matcher Matches ^ The beginning […]
REGEX / NOTES</>↗Regex31 Oct 2010
To create a single character class comprised of two or more separate character classes use unions. To create a union, simply nest one class inside the other, such as [0-3[7-9]]. package org.kodejava.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CharacterClassUnionDemo { public static void main(String[] args) { // Defines regex that matches the number 0, 1, […]
REGEX / NOTES</>↗Regex31 Oct 2010
You can use the && operator to combine classes that define a sets of characters. It will only match characters common to both classes (intersection). package org.kodejava.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CharacterClassIntersectionDemo { public static void main(String[] args) { // Define regex that will search characters from 'a' to 'z' // and is […]