Java Doc for MatchResult.java in  » Library » jakarta-oro-2.0.8 » org » apache » oro » text » regex » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » jakarta oro 2.0.8 » org.apache.oro.text.regex 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.apache.oro.text.regex.MatchResult

All known Subclasses:   org.apache.oro.text.awk.AwkMatchResult,  org.apache.oro.text.regex.Perl5MatchResult,  org.apache.oro.text.perl.Perl5Util,
MatchResult
public interface MatchResult (Code)
The MatchResult interface allows PatternMatcher implementors to return results storing match information in whatever format they like, while presenting a consistent way of accessing that information. However, MatchResult implementations should strictly follow the behavior described for the interface methods.

A MatchResult instance contains a pattern match and its saved groups. You can access the entire match directly using the MatchResult.group(int) method with an argument of 0, or by the MatchResult.toString() method which is defined to return the same thing. It is also possible to obtain the beginning and ending offsets of a match relative to the input producing the match by using the MatchResult.beginOffset(int) and MatchResult.endOffset(int) methods. The MatchResult.begin(int) and MatchResult.end(int) are useful in some circumstances and return the begin and end offsets of the subgroups of a match relative to the beginning of the match.

You might use a MatchResult as follows:

 int groups;
 PatternMatcher matcher;
 PatternCompiler compiler;
 Pattern pattern;
 PatternMatcherInput input;
 MatchResult result;
 compiler = new Perl5Compiler();
 matcher  = new Perl5Matcher();
 try {
 pattern = compiler.compile(somePatternString);
 } catch(MalformedPatternException e) {
 System.out.println("Bad pattern.");
 System.out.println(e.getMessage());
 return;
 }
 input   = new PatternMatcherInput(someStringInput);
 while(matcher.contains(input, pattern)) {
 result = matcher.getMatch();  
 // Perform whatever processing on the result you want.
 // Here we just print out all its elements to show how its
 // methods are used.
 System.out.println("Match: " + result.toString());
 System.out.println("Length: " + result.length());
 groups = result.groups();
 System.out.println("Groups: " + groups);
 System.out.println("Begin offset: " + result.beginOffset(0));
 System.out.println("End offset: " + result.endOffset(0));
 System.out.println("Saved Groups: ");
 // Start at 1 because we just printed out group 0
 for(int group = 1; group < groups; group++) {
 System.out.println(group + ": " + result.group(group));
 System.out.println("Begin: " + result.begin(group));
 System.out.println("End: " + result.end(group));
 }
 }
 

version:
   @version@
since:
   1.0
See Also:   PatternMatcher




Method Summary
public  intbegin(int group)
    
Parameters:
  group - The pattern subgroup.
public  intbeginOffset(int group)
     Returns an offset marking the beginning of the pattern match relative to the beginning of the input from which the match was extracted.


Parameters:
  group - The pattern subgroup.

public  intend(int group)
    
Parameters:
  group - The pattern subgroup.
public  intendOffset(int group)
     Returns an offset marking the end of the pattern match relative to the beginning of the input from which the match was extracted.


Parameters:
  group - The pattern subgroup.

public  Stringgroup(int group)
     Returns the contents of the parenthesized subgroups of a match, counting parentheses from left to right and starting from 1. Group 0 always refers to the entire match.
public  intgroups()
     The number of groups contained in the result.
public  intlength()
     A convenience method returning the length of the entire match.
public  StringtoString()
     Returns the same as group(0).



Method Detail
begin
public int begin(int group)(Code)

Parameters:
  group - The pattern subgroup. The offset into group 0 of the first token in the indicatedpattern subgroup. If a group was never matched or doesnot exist, returns -1. Be aware that a group that matchesthe null string at the end of a match will have an offsetequal to the length of the string, so you shouldn't blindlyuse the offset to index an array or String.



beginOffset
public int beginOffset(int group)(Code)
Returns an offset marking the beginning of the pattern match relative to the beginning of the input from which the match was extracted.


Parameters:
  group - The pattern subgroup. The offset of the first token in the indicatedpattern subgroup. If a group was never matched or doesnot exist, returns -1.




end
public int end(int group)(Code)

Parameters:
  group - The pattern subgroup. Returns one plus the offset into group 0 of the last token inthe indicated pattern subgroup. If a group was never matchedor does not exist, returns -1. A group matching the nullstring will return its start offset.



endOffset
public int endOffset(int group)(Code)
Returns an offset marking the end of the pattern match relative to the beginning of the input from which the match was extracted.


Parameters:
  group - The pattern subgroup. Returns one plus the offset of the last token inthe indicated pattern subgroup. If a group was never matchedor does not exist, returns -1. A group matching the nullstring will return its start offset.




group
public String group(int group)(Code)
Returns the contents of the parenthesized subgroups of a match, counting parentheses from left to right and starting from 1. Group 0 always refers to the entire match. For example, if the pattern foo(\d+) is used to extract a match from the input abfoo123 , then group(0) will return foo123 and group(1) will return 123 . group(2) will return null because there is only one subgroup in the original pattern.


Parameters:
  group - The pattern subgroup to return. A string containing the indicated pattern subgroup. Group0 always refers to the entire match. If a group was nevermatched, it returns null. This is not to be confused witha group matching the null string, which will return a Stringof length 0.




groups
public int groups()(Code)
The number of groups contained in the result. This numberincludes the 0th group. In other words, the result refersto the number of parenthesized subgroups plus the entire matchitself.



length
public int length()(Code)
A convenience method returning the length of the entire match. If you want to get the length of a particular subgroup you should use the MatchResult.group(int) method to get the string and then access its length() method as follows:

 int length = -1; // Use -1 to indicate group doesn't exist
 MatchResult result;
 String subgroup;
 // Initialization of result omitted
 subgroup = result.group(1);
 if(subgroup != null)
 length = subgroup.length();
 

The length() method serves as a more a more efficient way to do:

 length = result.group(0).length();
 

The length of the match.




toString
public String toString()(Code)
Returns the same as group(0). A string containing the entire match.



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.