REGEX / CATATAN</>↗Regex05 Nov 2010
Capturing groups are numbered by counting the opening parentheses from left to right. To find out how many groups are present in the expression, call the groupCount() method on a matcher object. The groupCount() method returns an int showing the number of capturing groups present in the matcher’s pattern. package org.kodejava.example.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; […]
REGEX / CATATAN</>↗Regex05 Nov 2010
This example show you how to attach quantifier to character classes or capturing group in regular expressions. package org.kodejava.example.regex; import java.util.regex.Pattern; import java.util.regex.Matcher; public class CombineWithQuantifier { public static void main(String[] args) { // [abc]{3} –> apply quantifier in character class. // Find 'a' or 'b' or 'c', three times in a row. // // […]
REGEX / CATATAN</>↗Regex05 Nov 2010
The reluctant quantifiers start the matcher at the beginning of the input string, then reluctantly eat one character at a time looking for a match. The last thing they try is the entire input string. package org.kodejava.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class ReluctantQuantifierDemo { public static void main(String[] args) { String[] expressions = {"x??", […]
REGEX / CATATAN</>↗Regex05 Nov 2010
The possessive quantifiers always eat the entire input string, trying once (and only once) for a match. Unlike the greedy quantifiers, possessive quantifiers never back off, even if doing so would allow the overall match to succeed. package org.kodejava.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; public class PossessiveQuantifierDemo { public static void main(String[] args) { String[] regexs […]
REGEX / CATATAN</>↗Regex05 Nov 2010
It’s also possible to enable various flags using embedded flag expressions. Embedded flag expressions are an alternative to the two-argument version of compile, and are specified in the regular expression itself. The example below is use (?i) flag expression to enable case-insensitive matching. Another flag expressions are listed below: (?x), equivalent with Pattern.COMMENTS (?m), equivalent […]
CORE API / CATATAN</>↗Core API05 Nov 2010
You can pause a current thread for a number of milliseconds by using the sleep() method of the Thread class. While the current thread is sleeping, it will allow other threads to execute. package org.kodejava.lang; public class ThreadSleepDemo implements Runnable { public static void main(String[] args) { Thread thread = new Thread(new ThreadSleepDemo()); thread.start(); } […]