REGEX / CATATAN</>↗Regex31 Okt 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 / CATATAN</>↗Regex31 Okt 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 […]
REGEX / CATATAN</>↗Regex31 Okt 2010
You can use subtraction to negate one or more nested character classes. This example creates a single character class that matches everything from a to z, except the vowels (‘a’, ‘i’, ‘u’, ‘e’, ‘o’). This can be written in a subtraction pattern as [a-z&&[^aiueo]]. package org.kodejava.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CharacterClassSubtractionDemo { public […]
REGEX / CATATAN</>↗Regex30 Okt 2010
A character class in the context of regular expression is a set of characters enclosed within a square brackets "[]". It specifies the characters that will successfully match a single character from the given input. A simple class, the most basic form of character class, is formed simply by placing a set of characters side-by-side […]
REGEX / CATATAN</>↗Regex30 Okt 2010
A negation class is a character class that begins with a ^ metacharacter which will exclude a set of defined characters within a square brackets. For example the negation class h[^ao]t in the example below match only the word hit and exclude the words hat and hot. package org.kodejava.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class […]
REGEX / CATATAN</>↗Regex30 Okt 2010
To define a character class that includes a range of values, put – metacharacter between the first and last character to be matched. For example [a-e]. You can also specify multiple ranges like this [a-zA-Z]. This will match any letter of the alphabet from a to z (lowercase) or A to Z (uppercase). In the […]