Regular expressions are a kind of language within a language, designed to help programmers with their searching task.
in general, a regex search runs from left to right, and once a source's character has been used in match, it can't be reused.
metacharacter:
To match a pattern exactly n number of times, simply specify the number inside a set of braces ex: a{3}
To require a pattern to appear at least n times, add a comma after the number a{3,}
Pattern pattern = Pattern.compile("regex");
Matcher matcher=pattern.matcher("String to look into");
matcher.find() start searching, matcher.group() for retrieving matched string
in general, a regex search runs from left to right, and once a source's character has been used in match, it can't be reused.
metacharacter:
- \d digit
- \s white space
- \w word character (letter, digit or "_")
- [a-f] range from a to f
[a-fA-F] looking for the occurrences of a-f or A-f not fA combination
- ^ to negate the character specified
- nested brackets to create a union set
- && to specify intersection of a set
- quantifiers "allows to specify number of occurrences to match against "
- + one or more
- * zero or more
- ? zero or one
- greedy: read first the whole string, if no match, move backward character by character till a match is found.
- reluctant , however, take the opposite approach: They start at the beginning of the input string, then move forward searching for match The last thing to try is the entire input string.
- moving from greedy to reluctant add ? so find? --> find??
To match a pattern exactly n number of times, simply specify the number inside a set of braces ex: a{3}
To require a pattern to appear at least n times, add a comma after the number a{3,}
Pattern pattern = Pattern.compile("regex");
Matcher matcher=pattern.matcher("String to look into");
matcher.find() start searching, matcher.group() for retrieving matched string
Comments
Post a Comment