├── docs ├── package-list ├── resources │ └── inherit.gif ├── packages.html ├── index.html ├── stylesheet.css ├── deprecated-list.html ├── allclasses-noframe.html ├── constant-values.html ├── allclasses-frame.html ├── serialized-form.html ├── help-doc.html ├── Split.html ├── GreedyExample.html ├── FindA.html ├── ReplaceExample.html ├── PatternSplit.html ├── ReluctantExample.html └── PossesiveExample.html ├── 1440.pdf ├── 1442.pdf ├── LICENSE.txt ├── util ├── RX.class ├── key ├── Spliter.class ├── GetGroup.class ├── RegexUtil.class ├── StrictRX.class ├── ReplaceString.class ├── RegexProperties.class ├── RegexUtil$LocalFileFilter.class ├── RX.java ├── Spliter.java ├── GetGroup.java ├── ReplaceString.java ├── StrictRX.java └── RegexProperties.java ├── META-INF └── MANIFEST.MF ├── 9781590591079.jpg ├── chapter1 ├── FindA.class ├── Split.class ├── MatchDates.class ├── MatchAddress.class ├── MatchZipCodes.class ├── ValidationTest.class ├── MatchNameFormats.class ├── MatchPhoneNumber.class ├── StyleSplitExample.class ├── MatchDuplicateWords.class ├── StyleSearchAndReplace.class ├── ValidationTestWithPatternAndMatcher.class ├── ValidationTest.java ├── ValidationTestWithPatternAndMatcher.java ├── Split.java ├── MatchZipCodes.java ├── MatchPhoneNumber.java ├── MatchNameFormats.java ├── MatchDates.java ├── FindA.java ├── MatchAddress.java ├── StyleSearchAndReplace.java ├── StyleSplitExample.java └── MatchDuplicateWords.java ├── chapter4 ├── Regex.class ├── LogDemo.class ├── XMLHelper.class ├── RegexProperties.class ├── ExceptionHandler.class ├── FileChannelExample.class ├── LogDemo.java ├── Regex.java ├── ExceptionHandler.java ├── XMLHelper.java ├── FileChannelExample.java └── RegexProperties.java ├── chapter5 ├── MatchDates.class ├── RegexUtil.class ├── MatchZipCodes.class ├── RegexProperties.class ├── MatchPhoneNumber.class ├── RegexUtil$LocalFileFilter.class ├── key.key ├── MatchPhoneNumber.java ├── MatchZipCodes.java └── MatchDates.java ├── chapter2 ├── PatternSplit.class ├── MatcherEndExample.class ├── MatcherFindExample.class ├── PattenMatchesTest.class ├── MatcherGroupExample.class ├── MatcherResetExample.class ├── MatcherStartExample.class ├── PatternMethodExample.class ├── MatcherEndParamExample.class ├── MatcherFindParamExample.class ├── MatcherLookingAtExample.class ├── MatcherMatchesExample.class ├── MatcherPatternExample.class ├── MatcherReplaceAllExample.class ├── MatcherStartParamExample.class ├── MatcherAppendReplacementExample.class ├── MatcherResetCharSequenceExample.class ├── PattenMatchesTest.java ├── MatcherPatternExample.java ├── MatcherGroupExample.java ├── MatcherReplaceAllExample.java ├── MatcherFindExample.java ├── PatternMethodExample.java ├── MatcherResetExample.java ├── MatcherResetCharSequenceExample.java ├── MatcherFindParamExample.java ├── MatcherAppendReplacementExample.java ├── MatcherEndExample.java ├── MatcherStartExample.java ├── PatternSplit.java ├── MatcherMatchesExample.java ├── MatcherLookingAtExample.java ├── MatcherEndParamExample.java └── MatcherStartParamExample.java ├── chapter3 ├── GreedyExample.class ├── ReplaceExample.class ├── PossesiveExample.class ├── ReluctantExample.class ├── SimpleGroupExample.class ├── SimpleSubGroupExample.class ├── NegativeLookBehindExample.class ├── NegativeLookaheadExample.class ├── PositiveLookaheadExample.class ├── SimpleGroupExample.java ├── GreedyExample.java ├── PositiveLookaheadExample.java ├── SimpleSubGroupExample.java ├── ReluctantExample.java ├── PossesiveExample.java ├── ReplaceExample.java ├── NegativeLookaheadExample.java └── NegativeLookBehindExample.java ├── 1429.html ├── README.md ├── contributing.md ├── readme.txt └── regex.properties /docs/package-list: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /1440.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/1440.pdf -------------------------------------------------------------------------------- /1442.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/1442.pdf -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/LICENSE.txt -------------------------------------------------------------------------------- /util/RX.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/util/RX.class -------------------------------------------------------------------------------- /util/key: -------------------------------------------------------------------------------- 1 | #java Method signature 2 | pattern1=\w\w+ 3 | 4 | all=^.*$ 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Created-By: 1.4.2 (Sun Microsystems Inc.) 3 | 4 | -------------------------------------------------------------------------------- /9781590591079.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/9781590591079.jpg -------------------------------------------------------------------------------- /util/Spliter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/util/Spliter.class -------------------------------------------------------------------------------- /chapter1/FindA.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/FindA.class -------------------------------------------------------------------------------- /chapter1/Split.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/Split.class -------------------------------------------------------------------------------- /chapter4/Regex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter4/Regex.class -------------------------------------------------------------------------------- /util/GetGroup.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/util/GetGroup.class -------------------------------------------------------------------------------- /util/RegexUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/util/RegexUtil.class -------------------------------------------------------------------------------- /util/StrictRX.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/util/StrictRX.class -------------------------------------------------------------------------------- /chapter4/LogDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter4/LogDemo.class -------------------------------------------------------------------------------- /chapter1/MatchDates.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/MatchDates.class -------------------------------------------------------------------------------- /chapter4/XMLHelper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter4/XMLHelper.class -------------------------------------------------------------------------------- /chapter5/MatchDates.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter5/MatchDates.class -------------------------------------------------------------------------------- /chapter5/RegexUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter5/RegexUtil.class -------------------------------------------------------------------------------- /util/ReplaceString.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/util/ReplaceString.class -------------------------------------------------------------------------------- /chapter1/MatchAddress.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/MatchAddress.class -------------------------------------------------------------------------------- /chapter1/MatchZipCodes.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/MatchZipCodes.class -------------------------------------------------------------------------------- /chapter2/PatternSplit.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/PatternSplit.class -------------------------------------------------------------------------------- /chapter3/GreedyExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter3/GreedyExample.class -------------------------------------------------------------------------------- /chapter5/MatchZipCodes.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter5/MatchZipCodes.class -------------------------------------------------------------------------------- /docs/resources/inherit.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/docs/resources/inherit.gif -------------------------------------------------------------------------------- /util/RegexProperties.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/util/RegexProperties.class -------------------------------------------------------------------------------- /chapter1/ValidationTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/ValidationTest.class -------------------------------------------------------------------------------- /chapter3/ReplaceExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter3/ReplaceExample.class -------------------------------------------------------------------------------- /chapter4/RegexProperties.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter4/RegexProperties.class -------------------------------------------------------------------------------- /chapter5/RegexProperties.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter5/RegexProperties.class -------------------------------------------------------------------------------- /chapter1/MatchNameFormats.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/MatchNameFormats.class -------------------------------------------------------------------------------- /chapter1/MatchPhoneNumber.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/MatchPhoneNumber.class -------------------------------------------------------------------------------- /chapter1/StyleSplitExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/StyleSplitExample.class -------------------------------------------------------------------------------- /chapter2/MatcherEndExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherEndExample.class -------------------------------------------------------------------------------- /chapter2/MatcherFindExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherFindExample.class -------------------------------------------------------------------------------- /chapter2/PattenMatchesTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/PattenMatchesTest.class -------------------------------------------------------------------------------- /chapter3/PossesiveExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter3/PossesiveExample.class -------------------------------------------------------------------------------- /chapter3/ReluctantExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter3/ReluctantExample.class -------------------------------------------------------------------------------- /chapter3/SimpleGroupExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter3/SimpleGroupExample.class -------------------------------------------------------------------------------- /chapter4/ExceptionHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter4/ExceptionHandler.class -------------------------------------------------------------------------------- /chapter4/FileChannelExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter4/FileChannelExample.class -------------------------------------------------------------------------------- /chapter5/MatchPhoneNumber.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter5/MatchPhoneNumber.class -------------------------------------------------------------------------------- /chapter1/MatchDuplicateWords.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/MatchDuplicateWords.class -------------------------------------------------------------------------------- /chapter2/MatcherGroupExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherGroupExample.class -------------------------------------------------------------------------------- /chapter2/MatcherResetExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherResetExample.class -------------------------------------------------------------------------------- /chapter2/MatcherStartExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherStartExample.class -------------------------------------------------------------------------------- /chapter2/PatternMethodExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/PatternMethodExample.class -------------------------------------------------------------------------------- /chapter1/StyleSearchAndReplace.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/StyleSearchAndReplace.class -------------------------------------------------------------------------------- /chapter2/MatcherEndParamExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherEndParamExample.class -------------------------------------------------------------------------------- /chapter2/MatcherFindParamExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherFindParamExample.class -------------------------------------------------------------------------------- /chapter2/MatcherLookingAtExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherLookingAtExample.class -------------------------------------------------------------------------------- /chapter2/MatcherMatchesExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherMatchesExample.class -------------------------------------------------------------------------------- /chapter2/MatcherPatternExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherPatternExample.class -------------------------------------------------------------------------------- /chapter3/SimpleSubGroupExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter3/SimpleSubGroupExample.class -------------------------------------------------------------------------------- /util/RegexUtil$LocalFileFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/util/RegexUtil$LocalFileFilter.class -------------------------------------------------------------------------------- /chapter2/MatcherReplaceAllExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherReplaceAllExample.class -------------------------------------------------------------------------------- /chapter2/MatcherStartParamExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherStartParamExample.class -------------------------------------------------------------------------------- /chapter3/NegativeLookBehindExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter3/NegativeLookBehindExample.class -------------------------------------------------------------------------------- /chapter3/NegativeLookaheadExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter3/NegativeLookaheadExample.class -------------------------------------------------------------------------------- /chapter3/PositiveLookaheadExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter3/PositiveLookaheadExample.class -------------------------------------------------------------------------------- /chapter5/RegexUtil$LocalFileFilter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter5/RegexUtil$LocalFileFilter.class -------------------------------------------------------------------------------- /chapter2/MatcherAppendReplacementExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherAppendReplacementExample.class -------------------------------------------------------------------------------- /chapter2/MatcherResetCharSequenceExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter2/MatcherResetCharSequenceExample.class -------------------------------------------------------------------------------- /chapter1/ValidationTestWithPatternAndMatcher.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/java-regular-expressions/HEAD/chapter1/ValidationTestWithPatternAndMatcher.class -------------------------------------------------------------------------------- /1429.html: -------------------------------------------------------------------------------- 1 | Chapter 1 Regular Expressions
2 | Chapter 2 Introduction to the Java.util.regex Object Model
3 | Chapter 3 Advanced Regex
4 | Chapter 4 Object-Oriented Regex
5 | Chapter 5 Practical Examples
6 | Appendix A Regular Expression Reference
7 | Appendix B Pattern and Matcher Methods
8 | Appendix C Common Regex Patterns -------------------------------------------------------------------------------- /chapter2/PattenMatchesTest.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | 3 | /** 4 | * Demonstrates usage of the 5 | * Pattern.matches method 6 | */ 7 | public class PattenMatchesTest{ 8 | public static void main(String args[]){ 9 | 10 | String regex = "ad*"; 11 | String input = "add"; 12 | 13 | boolean isMatch = Pattern.matches(regex,input); 14 | System.out.println(isMatch); 15 | } 16 | } -------------------------------------------------------------------------------- /chapter1/ValidationTest.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates very simple validation 4 | * 5 | * @author M Habibi 6 | * @version 1.0 2/22/04 7:57 PM 7 | */ 8 | 9 | public class ValidationTest{ 10 | public static void main(String args[]){ 11 | String candidate = "I love Java 4"; 12 | String pattern = "Java \\d"; 13 | System.out.println(candidate.matches(pattern)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chapter2/MatcherPatternExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | 3 | /** 4 | * Demonstrates usage of the 5 | * Matcher.pattern method 6 | */ 7 | public class MatcherPatternExample{ 8 | public static void main(String args[]){ 9 | test(); 10 | } 11 | 12 | public static void test(){ 13 | Pattern p = Pattern.compile("\\d"); 14 | Matcher m1 = p.matcher("55"); 15 | Matcher m2 = p.matcher("fdshfdgdfh"); 16 | 17 | System.out.println(m1.pattern() == m2.pattern()); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apress Source Code 2 | 3 | This repository accompanies [*Java Regular Expressions*](http://www.apress.com/9781590591079) by Mehran Habibi (Apress, 2004). 4 | 5 | ![Cover image](9781590591079.jpg) 6 | 7 | Download the files as a zip using the green button, or clone the repository to your machine using Git. 8 | 9 | ## Releases 10 | 11 | Release v1.0 corresponds to the code in the published book, without corrections or updates. 12 | 13 | ## Contributions 14 | 15 | See the file Contributing.md for more information on how you can contribute to this repository. 16 | -------------------------------------------------------------------------------- /chapter2/MatcherGroupExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates the usage of the 4 | * Matcher.group() method 5 | */ 6 | public class MatcherGroupExample{ 7 | public static void main(String args[]){ 8 | test(); 9 | } 10 | public static void test(){ 11 | //create a Pattern 12 | Pattern p = Pattern.compile("Bond"); 13 | 14 | //create a Matcher and use the Matcher.group() method 15 | String candidateString = "My name is Bond. James Bond."; 16 | Matcher matcher = p.matcher(candidateString); 17 | //extract the group 18 | matcher.find(); 19 | System.out.println(matcher.group()); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /chapter2/MatcherReplaceAllExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | import java.util.*; 3 | /** 4 | * Demonstrates usage of the 5 | * Matcher.replaceAll method 6 | */ 7 | public class MatcherReplaceAllExample{ 8 | public static void main(String args[]){ 9 | test(); 10 | } 11 | public static void test(){ 12 | //create a Pattern 13 | Pattern p = Pattern.compile("(i|I)ce"); 14 | 15 | //create the candidate String 16 | String candidateString = 17 | "I love ice. Ice's my favorite. Ice Ice Ice."; 18 | 19 | Matcher matcher = p.matcher(candidateString); 20 | String tmp = matcher.replaceAll("Java"); 21 | 22 | System.out.println( tmp ); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! -------------------------------------------------------------------------------- /chapter2/MatcherFindExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates the usage of the 4 | * Matcher.find method 5 | */ 6 | public class MatcherFindExample{ 7 | public static void main(String args[]){ 8 | test(); 9 | } 10 | public static void test(){ 11 | //create a Pattern 12 | Pattern p = Pattern.compile("Java"); 13 | 14 | //create the candidate String 15 | String candidateString = 16 | "I love Java. Java's my favorite language. Java Java Java."; 17 | 18 | //Attempt to match the candidate String. 19 | Matcher matcher = p.matcher(candidateString); 20 | 21 | //loop though and display all matches 22 | while (matcher.find()){ 23 | System.out.println(matcher.group()); 24 | } 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /chapter3/SimpleGroupExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates working with simple groups 4 | * 5 | * @author M Habibi 6 | * @version 1.0 2/22/04 7:46 PM 7 | */ 8 | 9 | public class SimpleGroupExample{ 10 | public static void main(String args[]){ 11 | //the original pattern is always group 0 12 | Pattern p = Pattern.compile("\\w\\d"); 13 | String candidate = "A9 is my favorite"; 14 | 15 | //if there is a match, extract that part of 16 | //the candidate string that matches group(0) 17 | Matcher matcher = p.matcher(candidate); 18 | 19 | //OUTPUT is 'A9' 20 | if (matcher.find()){ 21 | String tmp = matcher.group(0); 22 | System.out.println(tmp); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /docs/packages.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |
21 | 22 |
23 |
24 | The front page has been relocated.Please see: 25 |
26 |           Frame version 27 |
28 |           Non-frame version.
29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /chapter2/PatternMethodExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | 3 | /** 4 | * Demonstrates usage of the 5 | * Pattern.compile method 6 | */ 7 | public class PatternMethodExample{ 8 | public static void main(String args[]){ 9 | reusePatternMethodExample(); 10 | } 11 | 12 | public static void reusePatternMethodExample(){ 13 | //match a single digit 14 | Pattern p = Pattern.compile("\\d"); 15 | Matcher matcher = p.matcher("5"); 16 | boolean isOk = matcher.matches(); 17 | System.out.println("original pattern matches " + isOk); 18 | 19 | //recycle the pattern 20 | String tmp = p.pattern(); 21 | Pattern p2 = Pattern.compile(tmp); 22 | matcher = p.matcher("5"); 23 | isOk = matcher.matches(); 24 | System.out.println("second pattern matches " + isOk); 25 | } 26 | } -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Generated Documentation (Untitled) 8 | 9 | 10 | 11 | 12 | 13 | 14 | <H2> 15 | Frame Alert</H2> 16 | 17 | <P> 18 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. 19 | <BR> 20 | Link to<A HREF="ExceptionHandler.html">Non-frame version.</A> 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /chapter4/LogDemo.java: -------------------------------------------------------------------------------- 1 | import java.util.logging.*; 2 | 3 | /** 4 | * Demonstrates the usage of the log listener 5 | */ 6 | public class LogDemo{ 7 | public static void main(String args[]){ 8 | Logger log = Logger.global; 9 | setLoggerhandler(log); 10 | 11 | //test the code. Do even finest grade entries get 12 | //logged? 13 | log.finest(new Exception().toString()); 14 | } 15 | 16 | /** 17 | * Sets a logger handler for the given log. 18 | * @param log the logger which needs an listener 19 | * @version 1.0 5/12/2002 20 | */ 21 | public static void setLoggerhandler(Logger logger){ 22 | Handler handler = new ExceptionHandler(); 23 | logger.addHandler(handler); 24 | 25 | //set to handle all errors, so that it will examine 26 | //all errors. 27 | logger.setLevel(Level.ALL); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapter2/MatcherResetExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates the usage of the 4 | * Matcher.reset() method 5 | */ 6 | public class MatcherResetExample{ 7 | public static void main(String args[]){ 8 | test(); 9 | } 10 | public static void test(){ 11 | String output=""; 12 | //create a pattern, and extract a matcher 13 | Pattern p = Pattern.compile("\\d"); 14 | Matcher m1 = p.matcher("01234"); 15 | 16 | //exhaust the matcher 17 | while (m1.find()){ 18 | System.out.println("\t\t" + m1.group()); 19 | } 20 | //now reset the matcher to it's original state 21 | m1.reset(); 22 | System.out.println("After resetting the Matcher"); 23 | //iterate though the matcher again. 24 | //this would not be possible without 25 | while (m1.find()){ 26 | System.out.println("\t\t" + m1.group()); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /chapter1/ValidationTestWithPatternAndMatcher.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | 3 | 4 | /** 5 | * Demonstrates very simple validation using the 6 | * Patten and Matcher objects. 7 | * 8 | * @author M Habibi 9 | * @version 1.0 2/22/04 7:57 PM 10 | */ 11 | public class ValidationTestWithPatternAndMatcher{ 12 | public static void main(String args[]){ 13 | 14 | // Compile the pattern 15 | Pattern p = null; 16 | try{ 17 | p = Pattern.compile("Java \\d"); 18 | } 19 | catch (PatternSyntaxException pex){ 20 | pex.printStackTrace(); 21 | System.exit(0); 22 | } 23 | 24 | //define the matcher string 25 | 26 | String candidate = "I love Java 4"; 27 | //get the matcher 28 | Matcher m = p.matcher(candidate); 29 | 30 | if (m!=null) System.out.println(m.find()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapter2/MatcherResetCharSequenceExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates the usage of the 4 | * Matcher.reset(CharSequence) method 5 | */ 6 | public class MatcherResetCharSequenceExample{ 7 | public static void main(String args[]){ 8 | test(); 9 | } 10 | public static void test(){ 11 | String output=""; 12 | //create a pattern, and extract a matcher 13 | Pattern p = Pattern.compile("\\d"); 14 | Matcher m1 = p.matcher("01234"); 15 | 16 | //exhaust the matcher 17 | while (m1.find()){ 18 | System.out.println("\t\t" + m1.group()); 19 | } 20 | //now reset the matcher with new data 21 | m1.reset("56789"); 22 | System.out.println("After resetting the Matcher"); 23 | //iterate though the matcher again. 24 | //this would not be possible without 25 | while (m1.find()){ 26 | System.out.println("\t\t" + m1.group()); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /chapter3/GreedyExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | 3 | 4 | /** 5 | * Demonstrates usage of a greedy qualifier 6 | * 7 | * @author M Habibi 8 | * @version 1.0 2/22/04 7:46 PM 9 | */ 10 | 11 | public class GreedyExample{ 12 | public static void main(String args[]){ 13 | //define the pattern 14 | String regex = "(\\w+)(\\d\\d)(\\w+)"; 15 | 16 | //compile the pattern 17 | Pattern pattern = Pattern.compile(regex); 18 | 19 | //define the candidate string 20 | String candidate = "X99SuperJava"; 21 | 22 | //extract a matcher for the candidate string 23 | Matcher matcher = pattern.matcher(candidate); 24 | 25 | matcher.find(); 26 | 27 | //extract the matching groups 28 | System.out.println(matcher.group(1));//returns 'X' 29 | System.out.println(matcher.group(2));//returns '99' 30 | System.out.println(matcher.group(3));//returns Superjava 31 | } 32 | } -------------------------------------------------------------------------------- /chapter2/MatcherFindParamExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates the usage of the 4 | * Matcher.find(int) method 5 | */ 6 | public class MatcherFindParamExample{ 7 | public static void main(String args[]){ 8 | test(); 9 | } 10 | public static void test(){ 11 | //create a Pattern 12 | Pattern p = Pattern.compile("mice", Pattern.CASE_INSENSITIVE); 13 | 14 | //create the candidate String 15 | String candidateString = 16 | "I hate mice. I really hate MICE."; 17 | 18 | //Attempt to match the candidate String. 19 | Matcher matcher = p.matcher(candidateString); 20 | 21 | //display the latter match 22 | System.out.println(candidateString); 23 | matcher.find(11); 24 | System.out.println(matcher.group()); 25 | 26 | //display the earlier match 27 | System.out.println(candidateString); 28 | matcher.find(0); 29 | System.out.println(matcher.group()); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /chapter3/PositiveLookaheadExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates usage of a positive look ahead 4 | * 5 | * @author M Habibi 6 | * @version 1.0 2/22/04 7:46 PM 7 | */ 8 | 9 | public class PositiveLookaheadExample{ 10 | public static void main(String args[]){ 11 | //define the pattern 12 | String regex = "(?=^255).*"; 13 | 14 | //compile the pattern 15 | Pattern pattern = Pattern.compile(regex); 16 | 17 | //define the candidate string 18 | String candidate = "255.0.0.1"; 19 | 20 | //extract a matcher for the candidate string 21 | Matcher matcher = pattern.matcher(candidate); 22 | 23 | String ip ="not found"; 24 | 25 | //if the ip starts with 255, then the ip 26 | //will be populated with the correct information. 27 | if (matcher.find()) 28 | ip=matcher.group(); 29 | 30 | String msg ="ip: " + ip; 31 | 32 | System.out.println(msg); 33 | } 34 | } -------------------------------------------------------------------------------- /chapter2/MatcherAppendReplacementExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | import java.util.*; 3 | /** 4 | * Demonstrates usage of the 5 | * Matcher.appendReplacement method 6 | */ 7 | public class MatcherAppendReplacementExample{ 8 | public static void main(String args[]){ 9 | test(); 10 | } 11 | public static void test(){ 12 | //create a Pattern 13 | Pattern p = Pattern.compile("(\\w+) (\\w+)"); 14 | //create a StringBuffer 15 | StringBuffer sb =new StringBuffer(); 16 | 17 | //create the candidate Strings 18 | String candidateString = 19 | "James Bond"; 20 | 21 | String replacement = "$2, $1"; 22 | //Attempt to match the first candidate String 23 | Matcher matcher = p.matcher(candidateString); 24 | matcher.matches(); 25 | 26 | //populate the StringBufffer 27 | matcher.appendReplacement(sb,replacement); 28 | 29 | //display the output for the candidate 30 | String msg = sb.toString(); 31 | 32 | System.out.println( msg ); 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /chapter1/Split.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Demonstrates very simple String manipulation using 3 | * English synonyms. 4 | * 5 | * @author M Habibi 6 | * @version 1.0 2/22/04 7:58 PM 7 | */ 8 | 9 | public class Split{ 10 | public static void main(String args[]){ 11 | 12 | /*String statement = "I will not compromise. I will not "+ 13 | "cooperate. There will be no concession, no conciliation, no "+ 14 | "finding the middle group, and no give and take.";*/ 15 | 16 | String statement = "DOG"; 17 | 18 | String tokens[] =null; 19 | 20 | String splitPattern= "compromise|cooperate|concession|"+ 21 | "conciliation|(finding the middle group)|(give and take)"; 22 | 23 | tokens=statement.split(splitPattern); 24 | 25 | System.out.println("REGEX PATTERN:\n"+splitPattern + "\n"); 26 | 27 | System.out.println("STATEMENT:\n"+statement + "\n"); 28 | 29 | 30 | System.out.println("TOKENS:"); 31 | for (int i=0; i < tokens.length; i++){ 32 | System.out.println(tokens[i]); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /chapter4/Regex.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Holds a regex friendly object, so that we can try 3 | * persisting regex patterns as XML 4 | */ 5 | public class Regex implements java.io.Serializable{ 6 | 7 | /** 8 | * sets the String description 9 | * 10 | *@param String description 11 | */ 12 | public void setDescription(String description){ 13 | this.description = description; 14 | } 15 | 16 | /** 17 | * gets String description 18 | * 19 | *@return String description 20 | */ 21 | public String getDescription(){ 22 | return this.description; 23 | } 24 | 25 | /** 26 | * sets the String regex 27 | * 28 | *@param String regex 29 | */ 30 | public void setRegex(String regex){ 31 | this.regex = regex; 32 | } 33 | 34 | /** 35 | * gets String regex 36 | * 37 | *@return String regex 38 | */ 39 | public String getRegex(){ 40 | return this.regex; 41 | } 42 | 43 | private String regex; 44 | private String description; 45 | } 46 | -------------------------------------------------------------------------------- /chapter3/SimpleSubGroupExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates usage of a simple sub group 4 | * 5 | * @author M Habibi 6 | * @version 1.0 2/22/04 7:46 PM 7 | */ 8 | 9 | public class SimpleSubGroupExample{ 10 | public static void main(String args[]){ 11 | //the original pattern is always group 0 12 | Pattern p = Pattern.compile("\\w(\\d)"); 13 | String candidate = "A9 is my favorite"; 14 | 15 | //if there is a match, extract that parts that 16 | //matches. 17 | Matcher matcher = p.matcher(candidate); 18 | if (matcher.find()){ 19 | //Extract 'A9', which matches group(0), which is 20 | //always the entire pattern itself. 21 | String tmp = matcher.group(0); 22 | System.out.println(tmp); 23 | 24 | //extract part of the candidate string that matches 25 | //group(1): Namely, the '9' following the 'A' 26 | tmp = matcher.group(1); 27 | System.out.println(tmp); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /chapter2/MatcherEndExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates the usage of the 4 | * Matcher.start() method 5 | */ 6 | public class MatcherEndExample{ 7 | public static void main(String args[]){ 8 | test(); 9 | } 10 | public static void test(){ 11 | //create a Matcher and use the Matcher.end() method 12 | String candidateString = "My name is Bond. James Bond."; 13 | String matchHelper[] = 14 | {" ^"," ^"}; 15 | Pattern p = Pattern.compile("Bond"); 16 | Matcher matcher = p.matcher(candidateString); 17 | 18 | //Find the end point of the first 'Bond' 19 | matcher.find(); 20 | int endIndex = matcher.end(); 21 | System.out.println(candidateString); 22 | System.out.println(matchHelper[0] + endIndex); 23 | 24 | //Find the end point of the second 'Bond' 25 | matcher.find(); 26 | int nextIndex = matcher.end(); 27 | System.out.println(candidateString); 28 | System.out.println(matchHelper[1] + nextIndex); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /chapter2/MatcherStartExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates the usage of the 4 | * Matcher.start() method 5 | */ 6 | public class MatcherStartExample{ 7 | public static void main(String args[]){ 8 | test(); 9 | } 10 | public static void test(){ 11 | //create a Matcher and use the Matcher.start() method 12 | String candidateString = "My name is Bond. James Bond."; 13 | String matchHelper[] = 14 | {" ^"," ^"}; 15 | Pattern p = Pattern.compile("Bond"); 16 | Matcher matcher = p.matcher(candidateString); 17 | 18 | //Find the starting point of the first 'Bond' 19 | matcher.find(); 20 | int startIndex = matcher.start(); 21 | System.out.println(candidateString); 22 | System.out.println(matchHelper[0] + startIndex); 23 | 24 | //Find the starting point of the second 'Bond' 25 | matcher.find(); 26 | int nextIndex = matcher.start(); 27 | System.out.println(candidateString); 28 | System.out.println(matchHelper[1] + nextIndex); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /chapter3/ReluctantExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates usage of a Reluctant qualifier 4 | * 5 | * @author M Habibi 6 | * @version 1.0 2/22/04 7:46 PM 7 | */ 8 | 9 | public class ReluctantExample{ 10 | public static void main(String args[]){ 11 | //define the pattern 12 | String regex = "(\\d+?)"; 13 | //compile the pattern 14 | Pattern pattern = Pattern.compile(regex); 15 | 16 | //define the candidate string 17 | String candidate = "1234"; 18 | 19 | //extract a matcher for the candidate string 20 | Matcher matcher = pattern.matcher(candidate); 21 | 22 | while (matcher.find()){ 23 | //matches once for each digit 24 | //if this were not an example of 25 | //reluctant qualifier, it would match 26 | //exactly once, and that match would 27 | //include every digit in the candidate 28 | //string "1234". 29 | System.out.println(matcher.group()); 30 | 31 | } 32 | 33 | System.out.println("Done"); 34 | } 35 | } -------------------------------------------------------------------------------- /chapter2/PatternSplit.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | 3 | 4 | 5 | /** 6 | * Demonstrates usage of the Pattern split method 7 | * 8 | * @author M Habibi 9 | * @version 1.0 2/22/04 7:56 PM 10 | */ 11 | public class PatternSplit{ 12 | public static void main(String args[]) 13 | { 14 | String statement = "I will not compromise. I will not "+ 15 | "cooperate. There will be no concession, no conciliation, no "+ 16 | "finding the middle ground, and no give and take."; 17 | 18 | String splitPattern = "compromise|cooperate|concession|"+ 19 | "conciliation|(finding the middle ground)|(give and take)"; 20 | 21 | Pattern p = Pattern.compile(splitPattern); 22 | 23 | String[] tokens = p.split(statement); 24 | 25 | System.out.println("REGEX PATTERN:\n"+splitPattern+"\n"); 26 | System.out.println("STATEMENT:\n"+statement+"\n"); 27 | 28 | System.out.println("TOKENS:"); 29 | 30 | for (int i=0; i < tokens.length;i++) 31 | { 32 | System.out.println(tokens[i]); 33 | 34 | } 35 | 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /chapter3/PossesiveExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates usage of a possessive qualifier 4 | * 5 | * @author M Habibi 6 | * @version 1.0 2/22/04 7:46 PM 7 | */ 8 | 9 | public class PossesiveExample{ 10 | public static void main(String args[]){ 11 | //define the pattern 12 | String regex = "(\\w++)(\\d\\d)(\\w+)"; 13 | //compile the pattern 14 | Pattern pattern = Pattern.compile(regex); 15 | 16 | //define the candidate string 17 | String candidate = "X99SuperJava"; 18 | 19 | //extract a matcher for the candidate string 20 | Matcher matcher = pattern.matcher(candidate); 21 | 22 | if (matcher.find()){ 23 | System.out.println("GROUP 0:" + 24 | matcher.group(0)); 25 | System.out.println("GROUP 1:" + 26 | matcher.group(1)); 27 | System.out.println("GROUP 2:" + matcher.group(2)); 28 | System.out.println("GROUP 3:" + matcher.group(3)); 29 | } 30 | else{ 31 | System.out.println("NO MATCHES" ); 32 | } 33 | 34 | System.out.println("Done"); 35 | } 36 | } -------------------------------------------------------------------------------- /chapter1/MatchZipCodes.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Demonstrates very primitive zip code validation 4 | * 5 | * @author M Habibi 6 | * @version 1.0 2/22/04 7:58 PM 7 | */ 8 | import java.util.regex.*; 9 | import java.io.*; 10 | 11 | public class MatchZipCodes{ 12 | public static void main(String args[]){ 13 | isZipValid(args[0]); 14 | } 15 | 16 | /** 17 | * Confirms that the format for the given zip code is valid. 18 | * @param zip a String representing the zip code. 19 | * @returns true if the zip code format is acceptable. 20 | */ 21 | public static boolean isZipValid(String zip){ 22 | boolean retval=false; 23 | 24 | String zipCodePattern = "\\d{5}(-\\d{4})?"; 25 | retval = zip.matches(zipCodePattern); 26 | 27 | //prepare a message indicating success or failure 28 | String msg = " NO MATCH: pattern:" + zip 29 | + "\r\n regex: " + zipCodePattern; 30 | 31 | if (retval){ 32 | msg = " MATCH : pattern:" + zip 33 | + "\r\n regex: " + zipCodePattern; 34 | } 35 | 36 | System.out.println(msg +"\r\n"); 37 | return retval; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter1/MatchPhoneNumber.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates very primitive phone number validation 4 | * 5 | * @author M Habibi 6 | * @version 1.0 2/22/04 7:58 PM 7 | */ 8 | public class MatchPhoneNumber{ 9 | public static void main(String args[]){ 10 | isPhoneValid(args[0]); 11 | } 12 | 13 | /** 14 | * Confirms that the format for the given phone number is valid. 15 | * @param phone a String representing the phone number. 16 | * @returns true if the phone number format is acceptable. 17 | */ 18 | public static boolean isPhoneValid(String phone){ 19 | boolean retval=false; 20 | 21 | String phoneNumberPattern = 22 | "(\\d-)?(\\d{3}-)?\\d{3}-\\d{4}"; 23 | 24 | retval= phone.matches(phoneNumberPattern); 25 | 26 | //prepare a message indicating success or failure 27 | String msg = " NO MATCH: pattern:" + phone 28 | + "\r\n regex: " + phoneNumberPattern; 29 | 30 | if (retval){ 31 | msg = " MATCH : pattern:" + phone 32 | + "\r\n regex: " + phoneNumberPattern; 33 | } 34 | 35 | System.out.println(msg +"\r\n"); 36 | return retval; 37 | } 38 | } -------------------------------------------------------------------------------- /chapter3/ReplaceExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | 3 | /** 4 | * Demonstrates replacing text using regex 5 | * 6 | * @author M Habibi 7 | * @version 1.0 2/22/04 7:46 PM 8 | */ 9 | 10 | public class ReplaceExample{ 11 | public static void main(String args[]){ 12 | //define the pattern 13 | String regex = "(\\w)(\\d)(\\w+)"; 14 | 15 | //compile the pattern 16 | Pattern pattern = Pattern.compile(regex); 17 | 18 | //define the candidate string 19 | String candidate = "W3C"; 20 | 21 | //extract a matcher for the candidate string 22 | Matcher matcher = pattern.matcher(candidate); 23 | 24 | //return a new string that has replaced 25 | //every matching part of the candidate string 26 | //with whatever was found in the third group, 27 | //followed by the digit three 28 | String tmp = matcher.replaceAll("$33"); 29 | 30 | System.out.println("REPLACEMENT: " + tmp); 31 | //notice that the original candidate string 32 | //is unchanged, as expected. After all, strings 33 | //are immutable objects in java. 34 | System.out.println("ORIGINAL: " + candidate); 35 | } 36 | } -------------------------------------------------------------------------------- /chapter1/MatchNameFormats.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | 3 | /** 4 | * Demonstrates very primitive Name validation 5 | * 6 | * @author M Habibi 7 | * @version 1.0 2/22/04 7:58 PM 8 | */ 9 | public class MatchNameFormats{ 10 | public static void main(String args[]){ 11 | 12 | isNameValid(args[0]); 13 | } 14 | 15 | /** 16 | * Confirms that the format for the given name is valid. 17 | * @param name a String representing the name. 18 | * @returns true if the name format is acceptable. 19 | */ 20 | public static boolean isNameValid(String name){ 21 | boolean retval=false; 22 | 23 | String nameToken ="\\p{Upper}(\\p{Lower}+\\s?)"; 24 | 25 | //String nameToken ="A\\s?"; 26 | 27 | String namePattern = "("+nameToken+"){2,3}"; 28 | 29 | retval = name.matches(namePattern); 30 | 31 | //prepare a message indicating success or failure 32 | String msg = "NO MATCH: pattern:" + name 33 | + "\r\n regex :" + namePattern; 34 | 35 | if (retval){ 36 | msg = "MATCH pattern:" + name 37 | + "\r\n regex :" + namePattern; 38 | } 39 | 40 | System.out.println(msg +"\r\n"); 41 | return retval; 42 | } 43 | } -------------------------------------------------------------------------------- /chapter4/ExceptionHandler.java: -------------------------------------------------------------------------------- 1 | import java.util.logging.*; 2 | import java.util.regex.*; 3 | /** 4 | * Listens for exceptions in the log entries 5 | * @author M Habibi 6 | */ 7 | public class ExceptionHandler extends StreamHandler{ 8 | 9 | /** 10 | * examines the record being logged, and checks to see if 11 | * it contains an exception 12 | * @param record the LogRecord about to be logged 13 | */ 14 | public void publish(LogRecord record){ 15 | //extract the message 16 | String msg = record.getMessage(); 17 | 18 | //check to see the message contains an exception 19 | int exceptionIndex = msg.indexOf("Exception"); 20 | 21 | //if the message didn't contains the String 22 | //'Exception', then don't bother compiling the regex 23 | if (exceptionIndex > -1){ 24 | 25 | Pattern pattern = 26 | Pattern.compile("(.*Exception.*)"); 27 | 28 | Matcher matcher = pattern.matcher(msg); 29 | 30 | if (matcher != null && matcher.find()){ 31 | String err = "EXCEPTION FOUND " + matcher.group(1); 32 | System.out.println(err); 33 | //put emailer here 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /chapter1/MatchDates.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | import java.io.*; 3 | 4 | 5 | /** 6 | * Demonstrates very primitive date validation 7 | * 8 | * @author M Habibi 9 | * @version 1.0 2/22/04 7:58 PM 10 | */ 11 | public class MatchDates{ 12 | public static void main(String args[]){ 13 | isDateValid(args[0]); 14 | } 15 | 16 | /** 17 | * Confirms that given date format consists of one or two digits 18 | * followed by a hyphen, followed by one or two digits, followed 19 | * by a hypen, followed by four digits 20 | * @param date a String representing the date. 21 | * @returns true if data format is acceptable. 22 | */ 23 | public static boolean isDateValid(String date){ 24 | boolean retval=false; 25 | 26 | String datePattern ="\\d{1,2}-\\d{1,2}-\\d{4}"; 27 | retval = date.matches(datePattern); 28 | 29 | //prepare a message indicating success or failure 30 | String msg = " NO MATCH: pattern:" + date 31 | + "\r\n regexLength: " + datePattern; 32 | 33 | if (retval){ 34 | msg = " MATCH : pattern:" + date 35 | + "\r\n regexLength: " + datePattern; 36 | } 37 | 38 | System.out.println(msg +"\r\n"); 39 | return retval; 40 | } 41 | } -------------------------------------------------------------------------------- /chapter2/MatcherMatchesExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates the usage of the 4 | * Matcher.matches method 5 | */ 6 | public class MatcherMatchesExample{ 7 | public static void main(String args[]){ 8 | test(); 9 | } 10 | public static void test(){ 11 | //create a Pattern 12 | Pattern p = Pattern.compile("J2SE"); 13 | 14 | //create the candidate Strings 15 | String candidateString_1 = "j2se"; 16 | String candidateString_2 = "J2SE "; 17 | String candidateString_3 = "J2SE"; 18 | 19 | //Attempt to match the candidate Strings. 20 | Matcher matcher_1 = p.matcher(candidateString_1); 21 | Matcher matcher_2 = p.matcher(candidateString_2); 22 | Matcher matcher_3 = p.matcher(candidateString_3); 23 | 24 | //display the output for first candidate 25 | String msg = ":" + candidateString_1 + ": matches?: "; 26 | System.out.println( msg + matcher_1.matches()); 27 | 28 | //display the output for second candidate 29 | msg = ":" + candidateString_2 + ": matches?: "; 30 | System.out.println(msg + matcher_2.matches()); 31 | 32 | //display the output for third candidate 33 | msg = ":" + candidateString_3 + ": matches?: "; 34 | System.out.println(msg + matcher_3.matches()); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /chapter3/NegativeLookaheadExample.java: -------------------------------------------------------------------------------- 1 | import java.nio.channels.*; 2 | 3 | import java.util.regex.*; 4 | 5 | 6 | /** 7 | * Demonstrates usage of a negative look ahead 8 | * 9 | * @author M Habibi 10 | * @version 1.0 2/22/04 7:46 PM 11 | */ 12 | public class NegativeLookaheadExample{ 13 | public static void main(String args[]) 14 | throws Exception 15 | { 16 | //define the pattern 17 | String regex = "John (?!Smith)[A-Z]\\w+"; 18 | 19 | //compile the pattern 20 | Pattern pattern = Pattern.compile(regex); 21 | 22 | String candidate = "I think that John Smith "; 23 | candidate +="is a fictional character. His real name "; 24 | candidate +="might be John Jackson, John Westling, "; 25 | candidate +="or John Holmes. It might "; 26 | candidate +="just be John for all we know. "; 27 | 28 | 29 | //extract a matcher for the candidate string 30 | Matcher matcher = pattern.matcher(candidate); 31 | 32 | String tmp=null; 33 | 34 | //extract the matching group. Notice that it's 35 | //the default group, since lookarounds are non 36 | //capturing 37 | while (matcher.find()){ 38 | tmp=matcher.group(); 39 | System.out.println("MATCH:" + tmp); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /docs/stylesheet.css: -------------------------------------------------------------------------------- 1 | /* Javadoc style sheet */ 2 | 3 | /* Define colors, fonts and other style attributes here to override the defaults */ 4 | 5 | /* Page background color */ 6 | body { background-color: #FFFFFF } 7 | 8 | /* Headings */ 9 | h1 { font-size: 145% } 10 | 11 | /* Table colors */ 12 | .TableHeadingColor { background: #CCCCFF } /* Dark mauve */ 13 | .TableSubHeadingColor { background: #EEEEFF } /* Light mauve */ 14 | .TableRowColor { background: #FFFFFF } /* White */ 15 | 16 | /* Font used in left-hand frame lists */ 17 | .FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif } 18 | .FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif } 19 | .FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif } 20 | 21 | /* Navigation bar fonts and colors */ 22 | .NavBarCell1 { background-color:#EEEEFF;} /* Light mauve */ 23 | .NavBarCell1Rev { background-color:#00008B;} /* Dark Blue */ 24 | .NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;} 25 | .NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;} 26 | 27 | .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} 28 | .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF;} 29 | 30 | -------------------------------------------------------------------------------- /chapter5/key.key: -------------------------------------------------------------------------------- 1 | #Simple email address. assumes there are no comments, quotes, spaces, IPs, etc 2 | email=^(\p{Alnum}+(\.|\_|\-)?)*\p{Alnum}@(\p{Alnum}+(\.|\_|\-)?)*\p{Alpha}$ 3 | 4 | #Simple email address, but does allow IP addresses 5 | email_with_ip=^(\p{Alnum}+(\.|\_|\-)?)*\p{Alnum}@(((\p{Alnum}+(\.|\_|\-)?)*\p{Alpha})|((([0-1]?\d{1,2}\.)|(2[0-4]\d\.)|(25[0-5]\.)){3}(([0-1]?\d{1,2})|(2[0-4]\d)|(25[0-5]))))$ 6 | 7 | #Matches UK postcodes according to the following rules 1. LN NLL 8 | #eg N1 1AA 2. LLN NLL eg SW4 0QL 3. LNN NLL eg M23 4PJ 4. LLNN NLL 9 | #eg WS14 0JT 5. LLNL NLL eg SW1N 4TB 6. LNL NLL eg W1C 8LQ Thanks 10 | #to Simon Bell for informin ... 11 | zip=^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$ 12 | 13 | #This regular expression matches dates of the form XX/XX/YYYY 14 | #where XX can be 1 or 2 digits long and YYYY is always 4 15 | #digits long. 16 | dates=^\d{1,2}\/\d{1,2}\/\d{4}$ 17 | 18 | #valid IP addresses 19 | IP=(?:(?:[0-1]?\d{1,2}\.)|(?:2[0-4]\d\.)|(?:25[0-5]\.)){3}(?:(?:[0-1]?\d{1,2})|(?:2[0-4]\d)|(?:25[0-5])) 20 | IP_CAPTURING=(([0-1]?\d{1,2}\.)|(2[0-4]\d\.)|(25[0-5]\.)){3}(([0-1]?\d{1,2})|(2[0-4]\d)|(25[0-5])) 21 | 22 | #AM, VISA, DISCOVER, MASTERCARD 23 | credit_card=^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}$ 24 | 25 | #validates real numbers 26 | real_number=^[-+]?\d+(\.\d+)?$ -------------------------------------------------------------------------------- /chapter1/FindA.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | 3 | 4 | /** 5 | * Demonstrates finding all words that start with an 'a' 6 | * 7 | * @author M Habibi 8 | * @version 1.0 2/22/04 7:58 PM 9 | */ 10 | 11 | public class FindA{ 12 | public static void main(String args[]) 13 | throws Exception{ 14 | 15 | String candidate = 16 | "A Matcher examines the results of applying a pattern."; 17 | 18 | //define the matching pattern as a 19 | //word boundry, a lowercase a, any 20 | //number of immedietly trailing letters 21 | //numbers, or underscores, followed by 22 | //a word boundary 23 | String regex = "\\ba\\w*\\b"; 24 | Pattern p = Pattern.compile(regex); 25 | 26 | //extract the Matcher for the String text 27 | Matcher m = p.matcher(candidate); 28 | String val=null; 29 | 30 | //display the original input string 31 | System.out.println("INPUT: " + candidate); 32 | 33 | //display the search pattern 34 | System.out.println("REGEX: " + regex +"\r\n"); 35 | 36 | //examine the Matcher, and extract all 37 | //words starting with a lowercase a 38 | while (m.find()) 39 | { 40 | val = m.group(); 41 | System.out.println("MATCH: " + val); 42 | } 43 | 44 | //if there were no matches, say so 45 | if (val == null) { 46 | System.out.println("NO MATCHES: "); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | The classes in this jar comprise the examples used Java Regular Expressions, 2 | grouped by chapter number. For additional help, see the docs package. 3 | 4 | Additionally, there are some very useful classes in the 5 | util directory, which might help you as form your own examples. These are 6 | 7 | GetGroup.java 8 | - Extracts the indicated regex group number from the given text. 9 | 10 | RegexProperties.jva 11 | - Extends java.util.properties, and allows regex patterns to be externally 12 | stored. Further, it doesn't require that regex patterns be java-delimited. 13 | 14 | RegexUtil.java 15 | -Provides basic greplike functionality, but in a Java friendly way. For example, 16 | it offers a method which searches for occurrences of a pattern, then returns a 17 | java.util.Map which marks the line number of the matches as the key, and the 18 | actual match as the value. 19 | 20 | ReplaceString.java 21 | -quick utility for replacing one String with another using regex. Designed to 22 | help debug regex expressions quickly 23 | 24 | RX.java 25 | -Applies a regex pattern. Designed to help debug regex expressions quickly. 26 | 27 | Spliter.java 28 | -Splits a String along a regex pattern. Designed to help debug regex 29 | expressions quickly. 30 | 31 | StrictRX.java 32 | -Applies a regex pattern strictly: that is, only a perfect match will do. 33 | Designed to help debug regex expressions quickly. 34 | 35 | 36 | for comments, please email 37 | coach@influxs.com 38 | -------------------------------------------------------------------------------- /util/RX.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | import java.io.*; 3 | 4 | ///////////////////////////////////////////////////////////////////////////////////////////////// 5 | 6 | public class RX{ 7 | public static void main(String args[]){ 8 | 9 | 10 | if (args.length == 2){ 11 | match(args[0],args[1]); 12 | }else{ 13 | System.out.println("usage: target string first, regex second"); 14 | 15 | } 16 | 17 | } 18 | ///////////////////////////////////////////////////////////////////////////////////////////////// 19 | public static boolean match(String string, String regex){ 20 | // Compile the pattern 21 | boolean retval = false; 22 | Pattern p = null; 23 | 24 | p = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL); 25 | 26 | //count the number of matches. 27 | int matches = 0; 28 | 29 | //get the matcher 30 | Matcher m = p.matcher(string); 31 | String val=null; 32 | 33 | System.out.println(m.groupCount()); 34 | 35 | //find all matching Strings 36 | while (m.find()){ 37 | val = ":" + m.group() +":"; 38 | System.out.println(val); 39 | matches++; 40 | } 41 | 42 | //if there were no matches, then announce it. 43 | if (val == null){ 44 | System.out.println("NO MATCH"); 45 | }else{ 46 | retval= true; 47 | System.out.println(matches + " found"); 48 | } 49 | 50 | return retval; 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /chapter3/NegativeLookBehindExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | import java.util.logging.Logger; 3 | /** 4 | * Demonstrates usage of a negative behind ahead 5 | * 6 | * @author M Habibi 7 | * @version 1.0 2/22/04 7:46 PM 8 | */ 9 | 10 | public class NegativeLookBehindExample{ 11 | 12 | public static Logger log = Logger.getAnonymousLogger(); 13 | 14 | public static void main(String args[]) 15 | throws Exception 16 | { 17 | 18 | 19 | String regex="("; 20 | 21 | //compile the pattern 22 | Pattern pattern = Pattern.compile(regex); 23 | 24 | //extract a matcher for the candidate string 25 | String candidate = "Smithson"; 26 | Matcher matcher = pattern.matcher(candidate); 27 | 28 | //display output 29 | String msg=""; 30 | int counter =0; 31 | String tmp =null; 32 | while (matcher.find()) 33 | { 34 | int start = matcher.start(); 35 | int end = matcher.end(); 36 | 37 | tmp = ":"+matcher.group()+":"; 38 | msg +=tmp ; 39 | System.out.println("counter = " + counter); 40 | counter++; 41 | 42 | System.out.println("start = " + start); 43 | System.out.println("end = " + end); 44 | System.out.println("tmp = " + tmp); 45 | System.out.println("candidate.length() = " 46 | + candidate.length()+"\n"); 47 | } 48 | 49 | System.out.println(" MSG = :"+msg+":"); 50 | System.out.println("candidate = :"+candidate+":"); 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /chapter1/MatchAddress.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | import java.io.*; 3 | 4 | /** 5 | * Demonstrates very primitive address validation 6 | * 7 | * @author M Habibi 8 | * @version 1.0 2/22/04 7:58 PM 9 | */ 10 | 11 | public class MatchAddress{ 12 | public static void main(String args[]){ 13 | isAddressValid(args[0]); 14 | } 15 | 16 | /** 17 | * Confirms that the format for the given address is valid. 18 | * @param addr a String representing the address 19 | * @returns true if the zip code format is acceptable. 20 | */ 21 | public static boolean isAddressValid(String addr){ 22 | boolean retval = false; 23 | 24 | //use the name patten created earlier. 25 | String namePattern = 26 | "([A-Za-z])+ (([A-Za-z])+\\.? )?([A-Za-z])+\\s*"; 27 | 28 | //use the zip code patten created earlier. 29 | String zipCodePattern = "\\d{5}(-\\d{4})?"; 30 | 31 | //contruct am address pattern, 32 | String addressPattern = "^" + namePattern 33 | + "\\w+ .*, \\w+ " + zipCodePattern +"$"; 34 | 35 | retval= addr.matches(addressPattern); 36 | 37 | //prepare a message indicating success or failure 38 | String msg = " NO MATCH: pattern:" + addr 39 | + "\r\n regexLength: " 40 | + namePattern; 41 | 42 | if (retval){ 43 | msg = " MATCH : pattern:" + addr 44 | + "\r\n regexLength: " 45 | + namePattern; 46 | } 47 | 48 | System.out.println(msg +"\r\n"); 49 | return retval; 50 | } 51 | } -------------------------------------------------------------------------------- /chapter1/StyleSearchAndReplace.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Demonstrates very simple String manipulation using 3 | * English synonyms. 4 | * 5 | * @author M Habibi 6 | * @version 1.0 2/22/04 7:58 PM 7 | */ 8 | 9 | public class StyleSearchAndReplace{ 10 | public static void main(String args[]){ 11 | 12 | String statement = "The question as to whether the jab is"+ 13 | " superior to the cross has been debated for some time in"+ 14 | " boxing circles. However, it is my opinion that this"+ 15 | " false dichotomy misses the point. I call your attention"+ 16 | " to the fact that the best boxers often use a combination of"+ 17 | " the two. I call your attention to the fact that Mohammed"+ 18 | " Ali,the Greatest of the sport of boxing, used both. He had"+ 19 | " a tremendous jab, yet used his cross effectively, often, and"+ 20 | " well"; 21 | 22 | String newStmt= 23 | statement.replaceAll("The question as to whether","Whether"); 24 | 25 | newStmt= newStmt.replaceAll(" of the sport of boxing",""); 26 | newStmt=newStmt.replaceAll("amount of success","success"); 27 | newStmt= 28 | newStmt.replaceAll("However, it is my opinion that this","This"); 29 | 30 | newStmt= newStmt.replaceAll("a combination of the two","both"); 31 | newStmt= newStmt.replaceAll("This is in spite of the fact that" 32 | +" the", "The"); 33 | newStmt= 34 | newStmt.replaceAll("I call your attention to the fact that",""); 35 | 36 | System.out.println("BEFORE:\n"+statement + "\n"); 37 | System.out.println("AFTER:\n"+newStmt); 38 | } 39 | } -------------------------------------------------------------------------------- /chapter2/MatcherLookingAtExample.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | /** 3 | * Demonstrates the usage of the 4 | * Matcher.LookingAt method 5 | */ 6 | public class MatcherLookingAtExample{ 7 | public static void main(String args[]){ 8 | test(); 9 | } 10 | public static void test(){ 11 | //create a Pattern 12 | Pattern p = Pattern.compile("J2SE"); 13 | 14 | //create the candidate Strings 15 | String candidateString_1 = "J2SE is the only one for me"; 16 | String candidateString_2 = 17 | "For me, it's J2SE, or nothing at all"; 18 | String candidateString_3 = "J2SEistheonlyoneforme"; 19 | 20 | //Attempt to match the candidate Strings. 21 | Matcher matcher = p.matcher(candidateString_1); 22 | //display the output for the candidate 23 | String msg = ":" + candidateString_1 + ": matches?: "; 24 | System.out.println( msg + matcher.lookingAt()); 25 | 26 | matcher.reset(candidateString_2); 27 | //display the output for the candidates 28 | msg = ":" + candidateString_2 + ": matches?: "; 29 | System.out.println( msg + matcher.lookingAt()); 30 | 31 | matcher.reset(candidateString_3); 32 | //display the output for the candidate 33 | msg = ":" + candidateString_3 + ": matches?: "; 34 | System.out.println( msg + matcher.lookingAt()); 35 | 36 | /* 37 | *returns 38 | *:J2SE is the only one for me: matches?: true 39 | *:For me, it's J2SE, or nothing at all: matches?: false 40 | *:J2SEistheonlyoneforme: matches?: true 41 | */ 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /chapter1/StyleSplitExample.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | * Demonstrates very simple String manipulation using 5 | * English synonyms. 6 | * 7 | * @author M Habibi 8 | * @version 1.0 2/22/04 7:58 PM 9 | */ 10 | public class StyleSplitExample{ 11 | public static void main(String args[]){ 12 | String phrase1= "but simple justice, not charity"; 13 | strengthenSentence(phrase1); 14 | 15 | String phrase2= 16 | "but that I love Rome more, not that I love Ceaser less"; 17 | strengthenSentence(phrase2); 18 | 19 | String phrase3= 20 | "ask what you can do for your country, ask not what your " 21 | + "country can do for you"; 22 | strengthenSentence(phrase3); 23 | } 24 | 25 | /** 26 | * Splits and rearranges the given String, hopefully to a more 27 | * powerful effect. 28 | * @param sentence a String representing the phrase we want to 29 | * strengthen. 30 | * @returns a String representing the modified phrase. 31 | */ 32 | public static String strengthenSentence(String sentence){ 33 | String retval=null; 34 | 35 | String[] tokens = null; 36 | 37 | String splitPattern = 38 | ","; 39 | 40 | tokens= sentence.split(splitPattern); 41 | 42 | if (tokens==null){ 43 | String msg = " NO MATCH: pattern:" + sentence 44 | + "\r\n regex: " + splitPattern; 45 | } 46 | else{ 47 | retval = tokens[1] + ", " + tokens[0]; 48 | System.out.println("BEFORE: " + sentence); 49 | System.out.println("AFTER : " + retval +"\n"); 50 | } 51 | return retval; 52 | } 53 | } -------------------------------------------------------------------------------- /chapter4/XMLHelper.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.beans.*; 3 | 4 | /** 5 | * Helps persist an Serializable object to XML, 6 | * and back again. 7 | */ 8 | public class XMLHelper{ 9 | public static void main(String args[]){ 10 | Regex regex = new Regex(); 11 | regex.setRegex("<((?i)TITLE>)(.*?)String args[] 18 | * @throws Exception 19 | * 20 | * @author M Habibi 21 | */ 22 | public static void main(String args[]) throws Exception 23 | { 24 | 25 | if (args != null && args.length == 2) 26 | { 27 | int groupNum = Integer.parseInt(args[2]); 28 | 29 | String[] tmp = args[0].split(args[1]); 30 | display(tmp); 31 | 32 | } 33 | else if(args.length == 3 && args[0].equals("-f")){ 34 | String inputString = RegexUtil.getFileContent(args[1]); 35 | String[] tmp = inputString.split(args[2]); 36 | } 37 | else 38 | { 39 | String msg = "usage: \n"; 40 | msg += "usage:-f \n"; 41 | System.out.println(msg); 42 | } 43 | } 44 | 45 | /** 46 | * Displays the given String array 47 | * @param the String[] in 48 | * 49 | * @author M Habibi 50 | */ 51 | private static void display(String[] in) 52 | { 53 | if (in != null && in[0] != null) 54 | { 55 | 56 | for (int i=0; i )(\s*.*\s*) 6) 26 | { 27 | //load the regex properties file 28 | RegexProperties rb = new RegexProperties(); 29 | try 30 | { 31 | rb.load("../regex.properties"); 32 | } 33 | catch(Exception e) 34 | { 35 | e.printStackTrace(); 36 | } 37 | 38 | //scrub the phone number, removing spaces 39 | //and punctuation. We could store this 40 | //pattern in the regex .property file as well, 41 | //but it's not really so complex that's 42 | //it's confusing when java-delimited 43 | String tmp = phone.replaceAll("\\p{Punct}|\\s",""); 44 | 45 | //extract appropriate regex pattern and run check 46 | //in this case (\d{3})?\d{3}\d{4} 47 | String phoneNumberPattern=rb.getProperty(PHONE_NUMBER_KEY); 48 | 49 | //do the actual comparison 50 | retval= tmp.matches(phoneNumberPattern); 51 | 52 | //log for debug purposes 53 | msg += ":\r\nREGEX:" + phoneNumberPattern; 54 | } 55 | msg += "\r\nRESULT:" + retval +"\r\n"; 56 | log.info(msg); 57 | return retval; 58 | } 59 | public static void main(String args[]) throws Exception{ 60 | if (args != null && args.length == 1) 61 | System.out.println(isPhoneValid(args[0])); 62 | else 63 | System.out.println("usage: java MatchPhoneNumber "); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /chapter5/MatchZipCodes.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.logging.Logger; 3 | import java.util.regex.*; 4 | 5 | /** 6 | *Validates zip codes from the given country. 7 | *@author M Habibi 8 | */ 9 | public class MatchZipCodes{ 10 | private static Logger log = Logger.getAnonymousLogger(); 11 | private static final String ZIP_PATTERN="zip"; 12 | private static RegexProperties regexProperties; 13 | //load the regex properties file 14 | //do this at the class level 15 | static 16 | { 17 | try 18 | { 19 | regexProperties = new RegexProperties(); 20 | regexProperties.load("../regex.properties"); 21 | } 22 | catch(Exception e) 23 | { 24 | e.printStackTrace(); 25 | } 26 | } 27 | 28 | public static void main(String args[]){ 29 | String msg = "usage: java MatchZipCodes countryCode Zip"; 30 | 31 | if (args != null && args.length == 2) 32 | msg = ""+isZipValid(args[0],args[1]); 33 | 34 | //output either the usage message, or the results 35 | //of running the isZipValid method 36 | System.out.println(msg); 37 | } 38 | 39 | /** 40 | * Confirms that the format for the given zip code is valid. 41 | * @param the String countryCode 42 | * @param the String zip 43 | * @return boolean 44 | * 45 | * @author M Habibi 46 | */ 47 | public static boolean isZipValid(String countryCode, String zip) 48 | { 49 | boolean retval=false; 50 | //use the country code for form a unique into the regex 51 | //properties file 52 | String zipPatternKey = ZIP_PATTERN + countryCode.toUpperCase(); 53 | 54 | //extract the regex pattern for the given country code 55 | String zipPattern = regexProperties.getProperty(zipPatternKey); 56 | 57 | //if there was some sort of problem, don't bother trying 58 | //to execute the regex 59 | if (zipPattern != null) 60 | retval = zip.trim().matches(zipPattern); 61 | else 62 | { 63 | String msg = "regex for country code "+countryCode; 64 | msg+= " not found in property file "; 65 | log.warning(msg); 66 | } 67 | //create log report 68 | String msg = "regex="+zipPattern + 69 | "\nzip="+zip+"\nCountryCode="+ 70 | countryCode+"\nmatch result="+retval; 71 | log.finest(msg); 72 | 73 | return retval; 74 | } 75 | } -------------------------------------------------------------------------------- /util/GetGroup.java: -------------------------------------------------------------------------------- 1 | import java.util.logging.*; 2 | import java.util.regex.*; 3 | 4 | 5 | /** 6 | * A utility for extracting a specific regex group 7 | * from a given text which is either passed in or in a file. 8 | * Thus, for Java (\w)(\w)(\w).* 3 v is returned. 9 | * Alternately, the input 10 | * "-f" "GetGroup.java" " class\s+(.*)\s+\{" "1" 11 | * would return the name of this Class, "GetGroup" 12 | * @param the String args[] 13 | * @throws Exception 14 | * @author M Habibi 15 | * @version 1.0 2/22/04 6:17 PM 16 | */ 17 | public class GetGroup 18 | { 19 | private static Logger log = Logger.getAnonymousLogger(); 20 | 21 | /** 22 | * Extracts the indicated Group from the given 23 | * text. Thus, for Java (\w)(\w)(\w).* 3 24 | * v is returned. 25 | * Alternately, the input 26 | * "-f" "GetGroup.java" " class\s+(.*)\s+\{" "1" 27 | * would return the name of this Class, "GetGroup" 28 | * @param the String args[] 29 | * @throws Exception 30 | * 31 | * @author M Habibi 32 | */ 33 | public static void main(String args[]) throws Exception 34 | { 35 | 36 | if (args != null && args.length == 3) 37 | { 38 | int groupNum = Integer.parseInt(args[2]); 39 | 40 | findGroup(args[0],args[1],groupNum); 41 | 42 | } 43 | else if(args.length == 4 && args[0].equals("-f")){ 44 | String inputString = RegexUtil.getFileContent(args[1]); 45 | int groupNum = Integer.parseInt(args[3]); 46 | 47 | findGroup(inputString,args[2],groupNum); 48 | 49 | } 50 | else 51 | { 52 | String msg = "usage: \n"; 53 | msg += "usage: -f "; 54 | System.out.println(msg); 55 | 56 | } 57 | 58 | } 59 | 60 | /** 61 | * extracts the indicated Group from the given 62 | * text. Thus, for "Java" "(\w)(\w)(\w).*" "3" 63 | * v is returned. 64 | */ 65 | private static void findGroup(String text, String regex, int groupNum) 66 | { 67 | Pattern p = Pattern.compile(regex, Pattern.MULTILINE); 68 | 69 | Matcher m = p.matcher(text); 70 | 71 | if (m.find()) 72 | { 73 | String g = m.group(groupNum); 74 | 75 | System.out.println("group find =:"+ g+":"); 76 | } 77 | 78 | else 79 | { 80 | log.info("regex=:"+ regex+":"); 81 | log.info("groupNum=:"+ groupNum+":"); 82 | System.out.println("no matches found"); 83 | 84 | } 85 | 86 | 87 | 88 | 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /chapter5/MatchDates.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | import java.io.*; 3 | import java.util.logging.Logger; 4 | import java.util.GregorianCalendar; 5 | import java.util.Calendar; 6 | 7 | /** 8 | *Matches dates 9 | */ 10 | public class MatchDates{ 11 | private static final String PROP_FILE = "../regex.properties"; 12 | private static Logger log = Logger.getAnonymousLogger(); 13 | public static int LOWER_YEAR_LIMIT = -120; 14 | 15 | public static void main(String args[]) throws Exception{ 16 | if (args != null && args.length==1) 17 | { 18 | boolean b =isDateValid(args[0]); 19 | log.info(""+b); 20 | } 21 | else 22 | { 23 | System.out.println("usage: java MatchDates dd/dd/dddd"); 24 | } 25 | } 26 | 27 | /** 28 | * Confirms that given date format consists of one or two digits 29 | * followed by a punctuation, followed by one or two digits 30 | * followed by a hypen, followed by two or four digits. Further, 31 | * it actually validates that the date is less then today, and 32 | * and not more then LOWER_YEAR_LIMIT =120 years in 33 | * the past. This method even takes leap years and such into account 34 | * @param date a String representing the date. 35 | * @returns true if data format is acceptable. 36 | */ 37 | public static boolean isDateValid(String date) 38 | { 39 | boolean retval=false; 40 | 41 | String[] dateTokens = date.split("\\p{Punct}"); 42 | 43 | if (dateTokens.length == 3) 44 | { 45 | //Java months are zero based, so subtract 1 46 | int month = Integer.parseInt(dateTokens[0]) -1; 47 | int day = Integer.parseInt(dateTokens[1]); 48 | int year = Integer.parseInt(dateTokens[2]); 49 | 50 | //in case a 2 digit year was entered 51 | if (year < 100) 52 | year += 2000; 53 | 54 | //get boundary years 55 | GregorianCalendar today = new GregorianCalendar(); 56 | //get a lowerLimit that is LOWER_YEAR_LIMIT less then 57 | //today 58 | GregorianCalendar lowerLimit = new GregorianCalendar(); 59 | lowerLimit.add(Calendar.YEAR, LOWER_YEAR_LIMIT); 60 | 61 | //create a candidate representing the proposed date. 62 | GregorianCalendar candidate = 63 | new GregorianCalendar(year, month,day); 64 | 65 | //check the validity of the date 66 | if 67 | ( 68 | candidate.before(today) 69 | && 70 | candidate.after(lowerLimit) 71 | &&//month could be off, say the user entered 55 72 | month == candidate.get(Calendar.MONTH) 73 | &&//day could be off, say the user entered 55 74 | day == candidate.get(Calendar.DAY_OF_MONTH) 75 | ) 76 | { 77 | retval = true; 78 | } 79 | } 80 | return retval; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /util/ReplaceString.java: -------------------------------------------------------------------------------- 1 | import java.util.logging.*; 2 | import java.util.regex.*; 3 | 4 | /** 5 | * A utility for replace a subsection of a String with another String 6 | * from a given text which is either passed in or in a file. 7 | * Thus, for "hi Waldo" "hi" "hello", 8 | * hello Waldo is returned. 9 | * Alternately, the input 10 | * "-f" "ReplaceString.java" "ReplaceString" "NewClassName" 11 | * would return the text that makes up this class, but replaces 12 | * all instances of ReplaceString with NewClassName 13 | * @param the String args[] 14 | * @throws Exception 15 | * @author M Habibi 16 | * @version 1.0 2/22/04 6:17 PM 17 | */ 18 | public class ReplaceString 19 | { 20 | private static Logger log = Logger.getAnonymousLogger(); 21 | 22 | /** 23 | * For "hi Waldo" "hi" "hello", 24 | * hello Waldo is returned. 25 | * Alternately, the input 26 | * "-f" "ReplaceString.java" "ReplaceString" "NewClassName" 27 | * would return the text that makes up this class, but replaces 28 | * all instances of ReplaceString with NewClassName 29 | * @param the String args[] 30 | * @throws Exception 31 | * 32 | * @author M Habibi 33 | */ 34 | public static void main(String args[]) throws Exception 35 | { 36 | 37 | if (args != null && args.length == 3) 38 | { 39 | replaceString(args[0],args[1],args[2]); 40 | 41 | } 42 | else if (args != null && args.length == 4 && args[0].equals("-f")) 43 | { 44 | String inputString = RegexUtil.getFileContent(args[1]); 45 | replaceString(inputString,args[2],args[3]); 46 | 47 | } 48 | else 49 | { 50 | String msg = "usage: \n"; 51 | msg += "usage: -f "; 52 | System.out.println(msg); 53 | 54 | } 55 | } 56 | 57 | /** 58 | * For "hi Waldo" "hi" "hello", 59 | * hello Waldo is returned. 60 | * Alternately, the input 61 | * "-f" "ReplaceString.java" "ReplaceString" "NewClassName" 62 | * would return the text that makes up this class, but replaces 63 | * all instances of ReplaceString with NewClassName 64 | * @param the String text 65 | * @param the String regex 66 | * @param the String replace 67 | * @return String 68 | * 69 | * @author M Habibi 70 | */ 71 | private static String replaceString(String text, String regex, String replace) 72 | { 73 | String retval =null; 74 | Pattern p = Pattern.compile(regex); 75 | 76 | Matcher m = p.matcher(text); 77 | 78 | retval = m.replaceAll(replace); 79 | System.out.println("OUT=:"+ retval+":\n"); 80 | 81 | return retval; 82 | } 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /util/StrictRX.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | import java.util.logging.Logger; 3 | 4 | /** 5 | * Applies the given regex pattern to the text in the 6 | * strictest possible way. The text can be optionally 7 | * read in from a file. 8 | * 9 | * @author M Habibi 10 | * @version 1.0 2/22/04 6:57 PM 11 | */ 12 | public class StrictRX{ 13 | private static Logger log = Logger.getAnonymousLogger(); 14 | 15 | 16 | /** 17 | * Reads the users' input. 18 | * usage: java StrictRX 19 | * usage: java StrictRX target 20 | * usage: java StrictRX -f 21 | * where is the text 22 | * where is the pattern to apply 23 | * where is the name of the property file 24 | * which contains the regex we can to use 25 | * where is the name of the property in that property file 26 | * where is name of a file which contains 27 | * the text we want to apply the pattern to. 28 | * 29 | * @param the String args[] 30 | * @throws Exception 31 | * 32 | * @author M Habibi 33 | */ 34 | public static void main(String args[]) throws Exception{ 35 | if (args.length == 2){ 36 | compare(args[0],args[1]); 37 | } 38 | 39 | else if(args.length == 3 ){ 40 | 41 | log.info("args0=:"+ args[0]+":"); 42 | log.info("args1=:"+ args[1]+":"); 43 | log.info("args2=:"+ args[2]+":"); 44 | 45 | String pattern = RegexUtil.getProperty(args[1],args[2]); 46 | compare(args[0],pattern); 47 | } 48 | else if(args.length == 4 && args[0].equals("-f")){ 49 | 50 | log.info("args0=:"+ args[0]+":"); 51 | log.info("args1=:"+ args[1]+":"); 52 | log.info("args2=:"+ args[2]+":"); 53 | log.info("args3=:"+ args[3]+":"); 54 | 55 | String inputString = RegexUtil.getFileContent(args[1]); 56 | 57 | String pattern = RegexUtil.getProperty(args[2],args[3]); 58 | compare(inputString,pattern); 59 | } 60 | else{ 61 | System.out.println("usage: java StrictRX target regex"); 62 | System.out.println("usage: java StrictRX target "); 63 | System.out.println("usage: java StrictRX -f "); 64 | 65 | } 66 | } 67 | 68 | /** 69 | * Strictly compares the regex pattern to the given text 70 | * @param the String text 71 | * @param the String regex 72 | * 73 | * @author M Habibi 74 | */ 75 | public static void compare(String text, String regex){ 76 | 77 | //display the original input string 78 | System.out.println("INPUT:" + text+":"); 79 | //display the search pattern 80 | System.out.println("REGEX:" + regex +":\r\n"); 81 | 82 | if (text.matches(regex)) System.out.println ("MATCH: " + text); 83 | else System.out.println("NO MATCH"); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /docs/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Deprecated List 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 43 | 46 | 47 | 48 | 49 | 52 | 67 | 68 |
44 | 45 |
69 | 70 | 71 | 72 |
73 |
74 |

75 | Deprecated API

76 |
77 |
78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 98 | 101 | 102 | 103 | 104 | 107 | 122 | 123 |
99 | 100 |
124 | 125 | 126 | 127 |
128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /docs/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All Classes 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | All Classes 19 |
20 | 21 | 22 | 23 | 124 | 125 |
ExceptionHandler 24 |
25 | FileChannelExample 26 |
27 | FindA 28 |
29 | GetGroup 30 |
31 | GreedyExample 32 |
33 | LogDemo 34 |
35 | MatchAddress 36 |
37 | MatchDates 38 |
39 | MatchDuplicateWords 40 |
41 | MatchNameFormats 42 |
43 | MatchPhoneNumber 44 |
45 | MatchZipCodes 46 |
47 | MatcherAppendReplacementExample 48 |
49 | MatcherEndExample 50 |
51 | MatcherEndParamExample 52 |
53 | MatcherFindExample 54 |
55 | MatcherFindParamExample 56 |
57 | MatcherGroupExample 58 |
59 | MatcherLookingAtExample 60 |
61 | MatcherMatchesExample 62 |
63 | MatcherPatternExample 64 |
65 | MatcherReplaceAllExample 66 |
67 | MatcherResetCharSequenceExample 68 |
69 | MatcherResetExample 70 |
71 | MatcherStartExample 72 |
73 | MatcherStartParamExample 74 |
75 | NegativeLookBehindExample 76 |
77 | NegativeLookaheadExample 78 |
79 | PattenMatchesTest 80 |
81 | PatternMethodExample 82 |
83 | PatternSplit 84 |
85 | PositiveLookaheadExample 86 |
87 | PossesiveExample 88 |
89 | RX 90 |
91 | Regex 92 |
93 | RegexProperties 94 |
95 | RegexUtil 96 |
97 | ReluctantExample 98 |
99 | ReplaceExample 100 |
101 | ReplaceString 102 |
103 | SimpleGroupExample 104 |
105 | SimpleSubGroupExample 106 |
107 | Split 108 |
109 | Spliter 110 |
111 | StrictRX 112 |
113 | StyleSearchAndReplace 114 |
115 | StyleSplitExample 116 |
117 | ValidationTest 118 |
119 | ValidationTestWithPatternAndMatcher 120 |
121 | XMLHelper 122 |
123 |
126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /docs/constant-values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Constant Field Values 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 43 | 46 | 47 | 48 | 49 | 52 | 67 | 68 |
44 | 45 |
69 | 70 | 71 | 72 |
73 |
74 |

75 | Constant Field Values

76 |
77 |
78 | Contents
    79 |
80 | 81 |
82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 102 | 105 | 106 | 107 | 108 | 111 | 126 | 127 |
103 | 104 |
128 | 129 | 130 | 131 |
132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /chapter4/FileChannelExample.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.nio.*; 3 | import java.nio.channels.*; 4 | 5 | /** 6 | * Provides an easy mechinism for extracting the regex contents 7 | * of a file 8 | */ 9 | public class FileChannelExample{ 10 | public static void main(String args[]) throws IOException{ 11 | 12 | String targetFile = "FileChannelExample.java"; 13 | 14 | //if the user passed in a file to read, then use 15 | //that file instead 16 | if (args != null && args.length ==1) 17 | targetFile = args[0]; 18 | 19 | //getDataUsingFileChannel(targetFile); 20 | //getDataUsingInputStream(targetFile); 21 | getDataUsingMappedFileChannel(targetFile); 22 | 23 | } 24 | 25 | /** 26 | * Extracts data from a file by using FileChannels 27 | * @param targetFile the name and path of the file to read 28 | * @throws IOException if anything goes wrong 29 | */ 30 | public static void getDataUsingFileChannel(String targetFile) 31 | throws IOException{ 32 | //open a connection to the source code for this 33 | //class 34 | 35 | 36 | //measure how long this process takes, 37 | //so take the start time 38 | long startTime = System.currentTimeMillis(); 39 | 40 | FileInputStream fis = 41 | new FileInputStream(targetFile); 42 | 43 | //get a file channel 44 | FileChannel fc = fis.getChannel(); 45 | 46 | //create a ByteBuffer that is large enough 47 | //and read the contents of the file into it 48 | ByteBuffer bb = ByteBuffer.allocate((int)fc.size()); 49 | 50 | fc.read(bb); 51 | 52 | //set the ByteBuffer's position it it's begining 53 | bb.flip(); 54 | 55 | //save the content of the file as a String 56 | String fileContent= new String(bb.array()); 57 | 58 | //so take the end time 59 | long endTime = System.currentTimeMillis(); 60 | 61 | long totalTime = (endTime - startTime); 62 | 63 | //release the FileChannel 64 | fc.close(); 65 | fc = null; 66 | bb = null; 67 | 68 | //write out the contents of this file 69 | System.out.println("--getDataUsingFileChannel "); 70 | 71 | System.out.println("targetFile = " + targetFile); 72 | 73 | System.out.println("totalTime = " + totalTime); 74 | } 75 | 76 | /** 77 | * Extracts data from a file by using FileChannels 78 | * @param targetFile the name and path of the file to read 79 | * @throws IOException if anything goes wrong 80 | */ 81 | public static void getDataUsingMappedFileChannel(String targetFile) 82 | throws IOException{ 83 | //open a connection to the source code for this 84 | //class 85 | 86 | 87 | //measure how long this process takes, 88 | //so take the start time 89 | long startTime = System.currentTimeMillis(); 90 | 91 | FileInputStream fis = 92 | new FileInputStream(targetFile); 93 | 94 | //get a file channel 95 | FileChannel fc = fis.getChannel(); 96 | 97 | //map the byte buffer directly into memory 98 | fc.map(FileChannel.MapMode.READ_ONLY,0,(int)fc.size()); 99 | 100 | //create a ByteBuffer that is large enough 101 | //and read the contents of the file into it 102 | ByteBuffer bb = ByteBuffer.allocate((int)fc.size()); 103 | 104 | fc.read(bb); 105 | 106 | //set the ByteBuffer's position it it's begining 107 | bb.flip(); 108 | 109 | //save the content of the file as a String 110 | String fileContent= new String(bb.array()); 111 | 112 | //so take the end time 113 | long endTime = System.currentTimeMillis(); 114 | 115 | long totalTime = (endTime - startTime); 116 | 117 | //release the FileChannel 118 | fc.close(); 119 | fc = null; 120 | 121 | //write out the contents of this file 122 | System.out.println("--getDataUsingMappedFileChannel "); 123 | 124 | System.out.println("targetFile = " + targetFile); 125 | 126 | System.out.println("totalTime = " + totalTime); 127 | } 128 | 129 | /** 130 | * Extracts data from a file by using an InputStream 131 | * @param targetFile the name and path of the file to read 132 | * @throws IOException if anything goes wrong 133 | */ 134 | public static void getDataUsingInputStream(String targetFile) 135 | throws IOException{ 136 | //open a connection to the source code for this 137 | //class 138 | 139 | //measure how long this process takes, 140 | //so take the start time 141 | long startTime = System.currentTimeMillis(); 142 | 143 | File file = new File(targetFile); 144 | 145 | //get the size of the file 146 | int fileSize = (int)file.length(); 147 | 148 | FileInputStream fis = 149 | new FileInputStream(file); 150 | 151 | //create a byte[] that is large enough 152 | //and read the contents of the file into it 153 | byte[] byteArray = new byte[fileSize]; 154 | 155 | fis.read(byteArray); 156 | 157 | 158 | //save the content of the file as a String 159 | String fileContent= new String(byteArray); 160 | 161 | //so take the end time 162 | long endTime = System.currentTimeMillis(); 163 | 164 | long totalTime = (endTime - startTime); 165 | 166 | //release the file and stream 167 | fis.close(); 168 | fis = null; 169 | file = null; 170 | 171 | //write out the contents of this file 172 | System.out.println("--getDataUsingInputStream"); 173 | 174 | System.out.println("targetFile = " + targetFile); 175 | System.out.println("totalTime = " + totalTime); 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /docs/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All Classes 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | All Classes 19 |
20 | 21 | 22 | 23 | 124 | 125 |
ExceptionHandler 24 |
25 | FileChannelExample 26 |
27 | FindA 28 |
29 | GetGroup 30 |
31 | GreedyExample 32 |
33 | LogDemo 34 |
35 | MatchAddress 36 |
37 | MatchDates 38 |
39 | MatchDuplicateWords 40 |
41 | MatchNameFormats 42 |
43 | MatchPhoneNumber 44 |
45 | MatchZipCodes 46 |
47 | MatcherAppendReplacementExample 48 |
49 | MatcherEndExample 50 |
51 | MatcherEndParamExample 52 |
53 | MatcherFindExample 54 |
55 | MatcherFindParamExample 56 |
57 | MatcherGroupExample 58 |
59 | MatcherLookingAtExample 60 |
61 | MatcherMatchesExample 62 |
63 | MatcherPatternExample 64 |
65 | MatcherReplaceAllExample 66 |
67 | MatcherResetCharSequenceExample 68 |
69 | MatcherResetExample 70 |
71 | MatcherStartExample 72 |
73 | MatcherStartParamExample 74 |
75 | NegativeLookBehindExample 76 |
77 | NegativeLookaheadExample 78 |
79 | PattenMatchesTest 80 |
81 | PatternMethodExample 82 |
83 | PatternSplit 84 |
85 | PositiveLookaheadExample 86 |
87 | PossesiveExample 88 |
89 | RX 90 |
91 | Regex 92 |
93 | RegexProperties 94 |
95 | RegexUtil 96 |
97 | ReluctantExample 98 |
99 | ReplaceExample 100 |
101 | ReplaceString 102 |
103 | SimpleGroupExample 104 |
105 | SimpleSubGroupExample 106 |
107 | Split 108 |
109 | Spliter 110 |
111 | StrictRX 112 |
113 | StyleSearchAndReplace 114 |
115 | StyleSplitExample 116 |
117 | ValidationTest 118 |
119 | ValidationTestWithPatternAndMatcher 120 |
121 | XMLHelper 122 |
123 |
126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /util/RegexProperties.java: -------------------------------------------------------------------------------- 1 | import java.util.Properties; 2 | import java.util.regex.*; 3 | import java.util.*; 4 | import java.io.*; 5 | import java.nio.*; 6 | import java.nio.channels.*; 7 | import java.util.logging.Logger; 8 | 9 | /** 10 | * Provides a read-only extension of the java.util.properties file. 11 | * This class is unique because it is especially designed to read in 12 | * regular expressions which are not double delimited, as the String 13 | * class requires. Thus, \s is the actual string used to represent a 14 | * white space character, not \\s. Accordingly, this class does not allow 15 | * the regex patterns to be modified programmatically, nor does it 16 | * follow the normal property file convention for \n,\t, etc., or 17 | * multi line properties. Please see the documentation for the 18 | * load method 19 | */ 20 | public class RegexProperties extends Properties{ 21 | private static Logger log = Logger.getAnonymousLogger(); 22 | 23 | 24 | /** 25 | * loads the file. @See load(FileInputStream inStream) 26 | * 27 | * @param String the name of the file to load 28 | * @throws IOException if there's an IO problem 29 | * @throws PatternSyntaxException if the File format isn't properly 30 | * formed, per the specification given above. 31 | */ 32 | 33 | public void load(String inStream) 34 | throws IOException, PatternSyntaxException{ 35 | load(new FileInputStream(inStream)); 36 | } 37 | /** 38 | * Specialized property file for reading regular expressions 39 | * stored as properties. Reads a property list (key and 40 | * element pairs) from the input stream using a FileChannel, 41 | * thus allowing the usage of all characters. The stream is 42 | * assumed to be using the ISO 8859-1 character encoding. 43 | * Every property occupies one line of the input stream. Each 44 | * line is terminated by a line terminator (\n or \r or \r\n). 45 | * The entire contents of the file are read in. 46 | * 47 | A line that contains only white space or whose first 48 | * non-whitespace character is an ASCII # or ! is ignored 49 | * (thus, # or ! indicate comment lines). 50 | * 51 | * Every line other than a blank line or a comment line describes 52 | * one property to be added to the table. The key consists of 53 | * all the characters in the line starting with the first 54 | * non-whitespace character and up to, but not including, 55 | * the first ASCII =, :, or whitespace character. Any whitespace 56 | * after the key is skipped; if the first non-whitespace character 57 | * after the key is = or :, then it is ignored. White space character 58 | * after the = or ; are not skipped, and become part of the 59 | * value. This is a deliberate change from the default behavior of 60 | * the class, in order to support regular expressions, which may very 61 | * well need those characters. All remaining characters on the line 62 | * become part of the associated element string. If the last 63 | * character on the line is \, then the next line is not 64 | * treated as a continuation of the current line. Again, this is a 65 | * deliberate change from the default behavior of the class, in 66 | * order to support regular expressions. 67 | * 68 | * @param FileInputStream inStream the actual property file 69 | * @throws IOException if there's an IO problem 70 | * @throws PatternSyntaxException if the File format isn't properly 71 | * formed, per the specification given above. 72 | */ 73 | 74 | public void load(FileInputStream inStream) throws IOException, PatternSyntaxException{ 75 | // load the contents of the file 76 | FileChannel fc = inStream.getChannel(); 77 | 78 | ByteBuffer bb = ByteBuffer.allocate((int)fc.size()); 79 | fc.read(bb); 80 | bb.flip(); 81 | String fileContent = new String(bb.array()); 82 | 83 | //define a pattern that breaks the contents down line by line 84 | Pattern pattern = Pattern.compile("^(.*)$",Pattern.MULTILINE); 85 | Matcher matcher = pattern.matcher(fileContent); 86 | 87 | //iterate through the fileContent, line by line 88 | while (matcher.find()){ 89 | //extract the relevant part of each file. 90 | //in this case, relevant means the characters 91 | //between the beginning of the line and it's end 92 | String line = matcher.group(1) ; 93 | 94 | //if the line is null or a comment, ignore it 95 | if ( 96 | line != null && 97 | !"".equals(line.trim()) && 98 | !line.startsWith("#") && 99 | !line.startsWith("!") 100 | ) 101 | { 102 | String keyValue[] = null; 103 | 104 | 105 | //was the key- value entry split with the '=' 106 | //character or the ':' character? Both are legal. 107 | if (line.indexOf("=") > 0 ) 108 | keyValue = line.split("=",2);//only consume first = 109 | else 110 | keyValue = line.split(":",2);//only consume first : 111 | 112 | //final check that keyValue isn't null, because we 113 | //are going to be entering into a map, and trimming it 114 | if (keyValue != null) 115 | { 116 | super.put(keyValue[0].trim(),keyValue[1]); 117 | } 118 | } 119 | } 120 | 121 | fc = null; 122 | bb = null; 123 | } 124 | /** 125 | * Not supported. This is designed to be read only class 126 | * Throws UnsupportedOperationException. 127 | * @param String the key to be placed into this property 128 | * list. 129 | * @param String the value corresponding to key. 130 | * @throws UnsupportedOperationException 131 | * 132 | */ 133 | public void store(FileOutputStream out, String header) 134 | throws UnsupportedOperationException 135 | { 136 | String msg = "unsupported for this class"; 137 | throw new UnsupportedOperationException(msg); 138 | } 139 | /** 140 | * Not supported. 141 | * @param Object t - Mappings to be stored in this map. 142 | * 143 | * @returns nothing, since this call always throws an 144 | * UnsupportedOperationException. 145 | * @throws UnsupportedOperationException 146 | */ 147 | public void putAll(Map t) 148 | { 149 | String msg = "unsupported for this class"; 150 | throw new UnsupportedOperationException(msg); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /chapter4/RegexProperties.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Properties; 3 | import java.util.regex.*; 4 | import java.util.*; 5 | import java.io.*; 6 | import java.nio.*; 7 | import java.nio.channels.*; 8 | import java.util.logging.Logger; 9 | 10 | 11 | /** 12 | * Provides a read-only extension of the java.util.properties file. 13 | * This class is unique because it is especially designed to read in 14 | * regular expressions which are not double delimited, as the String 15 | * class requires. Thus, \s is the actual string used to represent a 16 | * whitespace character, not \\s. Accordingly, this class does not allow 17 | * the regex patterns to be modified programmatically, nor does it 18 | * follow the normal Property file convention for \n,\t, etc., 19 | * or multiline properties. Please see the documentation for the 20 | * load method. 21 | */ 22 | public class RegexProperties extends Properties{ 23 | private static Logger log = Logger.getAnonymousLogger(); 24 | private String fileContent=null; 25 | 26 | /** 27 | * loads the file. @See load(FileInputStream inStream) 28 | * 29 | * @param String the name of the file to load 30 | * @throws IOException if there's an IO problem 31 | * @throws PatternSyntaxException if the File format isn't properly 32 | * formed, per the specification given above. 33 | */ 34 | 35 | public void load(String inStream) 36 | throws IOException, PatternSyntaxException{ 37 | load(new FileInputStream(inStream)); 38 | } 39 | /** 40 | * Specialized property file for reading regular expressions 41 | * stored as properties. Reads a property list (key and 42 | * element pairs) from the input stream using a FileChannel, 43 | * thus allowing the usage of all characters. The stream is 44 | * assumed to be using the ISO 8859-1 character encoding. 45 | * Every property occupies one line of the input stream. Each 46 | * line is terminated by a line terminator (\n or \r or \r\n). 47 | * The entire contents of the file are read in. 48 | * 49 | A line that contains only whitespace or whose first 50 | * non-whitespace character is an ASCII # or ! is ignored 51 | * (thus, # or ! indicate comment lines). 52 | * 53 | * Every line other than a blank line or a comment line describes 54 | * one property to be added to the table. The key consists of 55 | * all the characters in the line starting with the first 56 | * non-whitespace character and up to, but not including, 57 | * the first ASCII =, :, or whitespace character. Any whitespace 58 | * after the key is skipped; if the first non-whitespace character 59 | * after the key is = or :, then it is ignored. White space character 60 | * after the = or ; are not skipped, and become part of the 61 | * value. This is a deliberate change from the default behavior of 62 | * the class, in order to support regular expressions, which may very 63 | * well need those characters. All remaining characters on the line 64 | * become part of the associated element string. If the last 65 | * character on the line is \, then the next line is not 66 | * treated as a continuation of the current line. Again, this is a 67 | * deliberate change from the default behavior of the class, in 68 | * order to support regular expressions. 69 | * 70 | * @param FileInputStream inStream the actual property file 71 | * @throws IOException if there's an IO problem 72 | * @throws PatternSyntaxException if the File format isn't properly 73 | * formed, per the specification given above. 74 | */ 75 | 76 | public void load(FileInputStream inStream) throws IOException, PatternSyntaxException{ 77 | // load the contents of the file 78 | FileChannel fc = inStream.getChannel(); 79 | 80 | ByteBuffer bb = ByteBuffer.allocate((int)fc.size()); 81 | fc.read(bb); 82 | bb.flip(); 83 | fileContent = new String(bb.array()); 84 | 85 | //define a pattern that breaks the contents down line by line 86 | Pattern pattern = Pattern.compile("^(.*)$",Pattern.MULTILINE); 87 | Matcher matcher = pattern.matcher(fileContent); 88 | 89 | //iterate through the fileContent, line by line 90 | while (matcher.find()){ 91 | //extract the relevant part of each file. 92 | //in this case, relevant means the characters 93 | //between the beginning of the line and it's end 94 | String line = matcher.group(1) ; 95 | 96 | //if the line is null or a comment, ignore it 97 | if ( 98 | line != null && 99 | !"".equals(line.trim()) && 100 | !line.startsWith("#") && 101 | !line.startsWith("!") 102 | ) 103 | { 104 | String keyValue[] = null; 105 | 106 | //was the kay-value entry split with the '=' 107 | //character or the ':' character? Both are legal. 108 | if (line.indexOf("=") > 0 ) 109 | keyValue = line.split("=",2); 110 | else 111 | keyValue = line.split(":",2); 112 | 113 | //final check that keyValue isn't null, because we 114 | //are going to be entering into a map, and trimming it 115 | if (keyValue != null) 116 | { 117 | super.put(keyValue[0].trim(),keyValue[1]); 118 | } 119 | } 120 | } 121 | 122 | fc = null; 123 | bb = null; 124 | } 125 | /** 126 | * Not supported. This is designed to be read only class 127 | * Throws UnsupportedOperationException. 128 | * @param String the key to be placed into this property 129 | * list. 130 | * @param String the value corresponding to key. 131 | * @throws UnsupportedOperationException 132 | * 133 | */ 134 | public void store(FileOutputStream out, String header) 135 | throws UnsupportedOperationException 136 | { 137 | String msg = "unsupported for this class"; 138 | throw new UnsupportedOperationException(msg); 139 | } 140 | /** 141 | * Not supported. 142 | * @param Object t - Mappings to be stored in this map. 143 | * 144 | * @returns nothing, since this call always throws an 145 | * UnsupportedOperationException. 146 | * @throws UnsupportedOperationException 147 | */ 148 | public void putAll(Map t) 149 | { 150 | String msg = "unsupported for this class"; 151 | throw new UnsupportedOperationException(msg); 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /docs/serialized-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Serialized Form 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 43 | 46 | 47 | 48 | 49 | 52 | 67 | 68 |
44 | 45 |
69 | 70 | 71 | 72 |
73 |
74 |

75 | Serialized Form

76 |
77 | 78 | 79 | 80 | 82 | 83 |
81 | Class Regex extends java.lang.Object implements Serializable
84 | 85 |

86 | 87 | 88 | 89 | 91 | 92 |
90 | Serialized Fields
93 | 94 |

95 | regex

96 |
 97 | java.lang.String regex
98 |
99 |
100 |
101 |
102 |
103 | 104 |

105 | description

106 |
107 | java.lang.String description
108 |
109 |
110 |
111 |
112 | 113 |

114 |


115 | 116 | 117 | 118 | 120 | 121 |
119 | Class RegexProperties extends java.util.Properties implements Serializable
122 | 123 |

124 | 125 | 126 | 127 | 129 | 130 |
128 | Serialized Fields
131 | 132 |

133 | fileContent

134 |
135 | java.lang.String fileContent
136 |
137 |
138 |
139 |
140 | 141 |

142 |


143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 163 | 166 | 167 | 168 | 169 | 172 | 187 | 188 |
164 | 165 |
189 | 190 | 191 | 192 |
193 | 194 | 195 | 196 | -------------------------------------------------------------------------------- /docs/help-doc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | API Help 8 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 43 | 46 | 47 | 48 | 49 | 52 | 67 | 68 |
44 | 45 |
69 | 70 | 71 | 72 |
73 |
74 |

75 | How This API Document Is Organized

76 |
77 | This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

78 | Package

79 |
80 | 81 |

82 | Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

    83 |
  • Interfaces (italic)
  • Classes
  • Exceptions
  • Errors
84 |
85 |

86 | Class/Interface

87 |
88 | 89 |

90 | Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    91 |
  • Class inheritance diagram
  • Direct Subclasses
  • All Known Subinterfaces
  • All Known Implementing Classes
  • Class/interface declaration
  • Class/interface description 92 |

    93 |

  • Nested Class Summary
  • Field Summary
  • Constructor Summary
  • Method Summary 94 |

    95 |

  • Field Detail
  • Constructor Detail
  • Method Detail
96 | Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
97 |

98 | Tree (Class Hierarchy)

99 |
100 | There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
    101 |
  • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
  • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
102 |
103 |

104 | Deprecated API

105 |
106 | The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
107 |

108 | Index

109 |
110 | The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
111 |

112 | Prev/Next

113 | These links take you to the next or previous class, interface, package, or related page.

114 | Frames/No Frames

115 | These links show and hide the HTML frames. All pages are available with or without frames. 116 |

117 |

118 | Serialized Form

119 | Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. 120 |

121 | 122 | 123 | This help file applies to API documentation generated using the standard doclet. 124 | 125 |
126 |


127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 147 | 150 | 151 | 152 | 153 | 156 | 171 | 172 |
148 | 149 |
173 | 174 | 175 | 176 |
177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /docs/Split.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Split 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 45 | 48 | 49 | 50 | 51 | 54 | 69 | 70 | 71 | 73 | 75 | 76 |
46 | 47 |
77 | 78 | 79 | 80 |
81 | 82 |

83 | Class Split

84 |
 85 | java.lang.Object
 86 |   extended bySplit
 87 | 
88 |
89 |
90 |
public class Split
extends java.lang.Object
91 | 92 |

93 | Demonstrates very simple String manipulation using 94 | English synonyms. 95 |

96 | 97 |

98 |


99 | 100 |

101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 114 | 115 | 116 | 120 | 121 |
113 | Constructor Summary
Split() 117 | 118 |
119 |            
122 |   123 | 124 | 125 | 126 | 127 | 128 | 130 | 131 | 132 | 134 | 138 | 139 |
129 | Method Summary
133 | static voidmain(java.lang.String[] args) 135 | 136 |
137 |            
140 |   141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 |
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
149 |   150 |

151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 162 | 163 |
161 | Constructor Detail
164 | 165 |

166 | Split

167 |
168 | public Split()
169 |
170 |
171 | 172 | 173 | 174 | 175 | 176 | 177 | 179 | 180 |
178 | Method Detail
181 | 182 |

183 | main

184 |
185 | public static void main(java.lang.String[] args)
186 |
187 |
188 |
189 |
190 |
191 | 192 |
193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 214 | 217 | 218 | 219 | 220 | 223 | 238 | 239 | 240 | 242 | 244 | 245 |
215 | 216 |
246 | 247 | 248 | 249 |
250 | 251 | 252 | 253 | -------------------------------------------------------------------------------- /docs/GreedyExample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | GreedyExample 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 45 | 48 | 49 | 50 | 51 | 54 | 69 | 70 | 71 | 73 | 75 | 76 |
46 | 47 |
77 | 78 | 79 | 80 |
81 | 82 |

83 | Class GreedyExample

84 |
 85 | java.lang.Object
 86 |   extended byGreedyExample
 87 | 
88 |
89 |
90 |
public class GreedyExample
extends java.lang.Object
91 | 92 |

93 | Demonstrates usage of a greedy qualifier 94 |

95 | 96 |

97 |


98 | 99 |

100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 113 | 114 | 115 | 119 | 120 |
112 | Constructor Summary
GreedyExample() 116 | 117 |
118 |            
121 |   122 | 123 | 124 | 125 | 126 | 127 | 129 | 130 | 131 | 133 | 137 | 138 |
128 | Method Summary
132 | static voidmain(java.lang.String[] args) 134 | 135 |
136 |            
139 |   140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
148 |   149 |

150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 161 | 162 |
160 | Constructor Detail
163 | 164 |

165 | GreedyExample

166 |
167 | public GreedyExample()
168 |
169 |
170 | 171 | 172 | 173 | 174 | 175 | 176 | 178 | 179 |
177 | Method Detail
180 | 181 |

182 | main

183 |
184 | public static void main(java.lang.String[] args)
185 |
186 |
187 |
188 |
189 |
190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 213 | 216 | 217 | 218 | 219 | 222 | 237 | 238 | 239 | 241 | 243 | 244 |
214 | 215 |
245 | 246 | 247 | 248 |
249 | 250 | 251 | 252 | -------------------------------------------------------------------------------- /docs/FindA.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | FindA 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 45 | 48 | 49 | 50 | 51 | 54 | 69 | 70 | 71 | 73 | 75 | 76 |
46 | 47 |
77 | 78 | 79 | 80 |
81 | 82 |

83 | Class FindA

84 |
 85 | java.lang.Object
 86 |   extended byFindA
 87 | 
88 |
89 |
90 |
public class FindA
extends java.lang.Object
91 | 92 |

93 | Demonstrates finding all words that start with an 'a' 94 |

95 | 96 |

97 |


98 | 99 |

100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 113 | 114 | 115 | 119 | 120 |
112 | Constructor Summary
FindA() 116 | 117 |
118 |            
121 |   122 | 123 | 124 | 125 | 126 | 127 | 129 | 130 | 131 | 133 | 137 | 138 |
128 | Method Summary
132 | static voidmain(java.lang.String[] args) 134 | 135 |
136 |            
139 |   140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
148 |   149 |

150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 161 | 162 |
160 | Constructor Detail
163 | 164 |

165 | FindA

166 |
167 | public FindA()
168 |
169 |
170 | 171 | 172 | 173 | 174 | 175 | 176 | 178 | 179 |
177 | Method Detail
180 | 181 |

182 | main

183 |
184 | public static void main(java.lang.String[] args)
185 |                  throws java.lang.Exception
186 |
187 |
188 | 189 |
Throws: 190 |
java.lang.Exception
191 |
192 |
193 | 194 |
195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 216 | 219 | 220 | 221 | 222 | 225 | 240 | 241 | 242 | 244 | 246 | 247 |
217 | 218 |
248 | 249 | 250 | 251 |
252 | 253 | 254 | 255 | -------------------------------------------------------------------------------- /docs/ReplaceExample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ReplaceExample 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 45 | 48 | 49 | 50 | 51 | 54 | 69 | 70 | 71 | 73 | 75 | 76 |
46 | 47 |
77 | 78 | 79 | 80 |
81 | 82 |

83 | Class ReplaceExample

84 |
 85 | java.lang.Object
 86 |   extended byReplaceExample
 87 | 
88 |
89 |
90 |
public class ReplaceExample
extends java.lang.Object
91 | 92 |

93 | Demonstrates replacing text using regex 94 |

95 | 96 |

97 |


98 | 99 |

100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 113 | 114 | 115 | 119 | 120 |
112 | Constructor Summary
ReplaceExample() 116 | 117 |
118 |            
121 |   122 | 123 | 124 | 125 | 126 | 127 | 129 | 130 | 131 | 133 | 137 | 138 |
128 | Method Summary
132 | static voidmain(java.lang.String[] args) 134 | 135 |
136 |            
139 |   140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
148 |   149 |

150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 161 | 162 |
160 | Constructor Detail
163 | 164 |

165 | ReplaceExample

166 |
167 | public ReplaceExample()
168 |
169 |
170 | 171 | 172 | 173 | 174 | 175 | 176 | 178 | 179 |
177 | Method Detail
180 | 181 |

182 | main

183 |
184 | public static void main(java.lang.String[] args)
185 |
186 |
187 |
188 |
189 |
190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 213 | 216 | 217 | 218 | 219 | 222 | 237 | 238 | 239 | 241 | 243 | 244 |
214 | 215 |
245 | 246 | 247 | 248 |
249 | 250 | 251 | 252 | -------------------------------------------------------------------------------- /docs/PatternSplit.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | PatternSplit 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 45 | 48 | 49 | 50 | 51 | 54 | 69 | 70 | 71 | 73 | 75 | 76 |
46 | 47 |
77 | 78 | 79 | 80 |
81 | 82 |

83 | Class PatternSplit

84 |
 85 | java.lang.Object
 86 |   extended byPatternSplit
 87 | 
88 |
89 |
90 |
public class PatternSplit
extends java.lang.Object
91 | 92 |

93 | Demonstrates usage of the Pattern split method 94 |

95 | 96 |

97 |


98 | 99 |

100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 113 | 114 | 115 | 119 | 120 |
112 | Constructor Summary
PatternSplit() 116 | 117 |
118 |            
121 |   122 | 123 | 124 | 125 | 126 | 127 | 129 | 130 | 131 | 133 | 137 | 138 |
128 | Method Summary
132 | static voidmain(java.lang.String[] args) 134 | 135 |
136 |            
139 |   140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
148 |   149 |

150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 161 | 162 |
160 | Constructor Detail
163 | 164 |

165 | PatternSplit

166 |
167 | public PatternSplit()
168 |
169 |
170 | 171 | 172 | 173 | 174 | 175 | 176 | 178 | 179 |
177 | Method Detail
180 | 181 |

182 | main

183 |
184 | public static void main(java.lang.String[] args)
185 |
186 |
187 |
188 |
189 |
190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 213 | 216 | 217 | 218 | 219 | 222 | 237 | 238 | 239 | 241 | 243 | 244 |
214 | 215 |
245 | 246 | 247 | 248 |
249 | 250 | 251 | 252 | -------------------------------------------------------------------------------- /docs/ReluctantExample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ReluctantExample 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 45 | 48 | 49 | 50 | 51 | 54 | 69 | 70 | 71 | 73 | 75 | 76 |
46 | 47 |
77 | 78 | 79 | 80 |
81 | 82 |

83 | Class ReluctantExample

84 |
 85 | java.lang.Object
 86 |   extended byReluctantExample
 87 | 
88 |
89 |
90 |
public class ReluctantExample
extends java.lang.Object
91 | 92 |

93 | Demonstrates usage of a Reluctant qualifier 94 |

95 | 96 |

97 |


98 | 99 |

100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 113 | 114 | 115 | 119 | 120 |
112 | Constructor Summary
ReluctantExample() 116 | 117 |
118 |            
121 |   122 | 123 | 124 | 125 | 126 | 127 | 129 | 130 | 131 | 133 | 137 | 138 |
128 | Method Summary
132 | static voidmain(java.lang.String[] args) 134 | 135 |
136 |            
139 |   140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
148 |   149 |

150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 161 | 162 |
160 | Constructor Detail
163 | 164 |

165 | ReluctantExample

166 |
167 | public ReluctantExample()
168 |
169 |
170 | 171 | 172 | 173 | 174 | 175 | 176 | 178 | 179 |
177 | Method Detail
180 | 181 |

182 | main

183 |
184 | public static void main(java.lang.String[] args)
185 |
186 |
187 |
188 |
189 |
190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 213 | 216 | 217 | 218 | 219 | 222 | 237 | 238 | 239 | 241 | 243 | 244 |
214 | 215 |
245 | 246 | 247 | 248 |
249 | 250 | 251 | 252 | -------------------------------------------------------------------------------- /docs/PossesiveExample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | PossesiveExample 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 45 | 48 | 49 | 50 | 51 | 54 | 69 | 70 | 71 | 73 | 75 | 76 |
46 | 47 |
77 | 78 | 79 | 80 |
81 | 82 |

83 | Class PossesiveExample

84 |
 85 | java.lang.Object
 86 |   extended byPossesiveExample
 87 | 
88 |
89 |
90 |
public class PossesiveExample
extends java.lang.Object
91 | 92 |

93 | Demonstrates usage of a possessive qualifier 94 |

95 | 96 |

97 |


98 | 99 |

100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 113 | 114 | 115 | 119 | 120 |
112 | Constructor Summary
PossesiveExample() 116 | 117 |
118 |            
121 |   122 | 123 | 124 | 125 | 126 | 127 | 129 | 130 | 131 | 133 | 137 | 138 |
128 | Method Summary
132 | static voidmain(java.lang.String[] args) 134 | 135 |
136 |            
139 |   140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
148 |   149 |

150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 161 | 162 |
160 | Constructor Detail
163 | 164 |

165 | PossesiveExample

166 |
167 | public PossesiveExample()
168 |
169 |
170 | 171 | 172 | 173 | 174 | 175 | 176 | 178 | 179 |
177 | Method Detail
180 | 181 |

182 | main

183 |
184 | public static void main(java.lang.String[] args)
185 |
186 |
187 |
188 |
189 |
190 | 191 |
192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 213 | 216 | 217 | 218 | 219 | 222 | 237 | 238 | 239 | 241 | 243 | 244 |
214 | 215 |
245 | 246 | 247 | 248 |
249 | 250 | 251 | 252 | --------------------------------------------------------------------------------