Java Doc for Pattern.java in  » Scripting » jruby » jregex » 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 » Scripting » jruby » jregex 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   jregex.Pattern

All known Subclasses:   jregex.util.io.PathPattern,  jregex.WildcardPattern,
Pattern
public class Pattern implements Serializable,REFlags(Code)
A handle for a precompiled regular expression.
To match a regular expression myExpr against a text myString one should first create a Pattern object:
 Pattern p=new Pattern(myExpr);
 
then obtain a Matcher object:
 Matcher matcher=p.matcher(myText);
 
The latter is an automaton that actually performs a search. It provides the following methods:
  • search for matching substrings : matcher.find() or matcher.findAll();
  • test whether the text matches the whole pattern : matcher.matches();
  • test whether the text matches the beginning of the pattern : matcher.matchesPrefix();
  • search with custom options : matcher.find(int options)

    Flags
    Flags (see REFlags interface) change the meaning of some regular expression elements at compiletime. These flags may be passed both as string(see Pattern(String,String)) and as bitwise OR of:

  • REFlags.IGNORE_CASE - enables case insensitivity
  • REFlags.MULTILINE - forces "^" and "$" to match both at the start and the end of line;
  • REFlags.DOTALL - forces "." to match eols('\r' and '\n' in ASCII);
  • REFlags.IGNORE_SPACES - literal spaces in expression are ignored for better readability;
  • REFlags.UNICODE - the predefined classes('\w','\d',etc) are referenced to Unicode;
  • REFlags.XML_SCHEMA - permits XML Schema regular expressions syntax extentions.

    Multithreading
    Pattern instances are thread-safe, i.e. the same Pattern object may be used by any number of threads simultaniously. On the other hand, the Matcher objects are NOT thread safe, so, given a Pattern instance, each thread must obtain and use its own Matcher.
    See Also:   REFlags
    See Also:   Matcher
    See Also:   Matcher.setTarget(java.lang.String)
    See Also:   Matcher.setTarget(java.lang.Stringintint)
    See Also:   Matcher.setTarget(char[]intint)
    See Also:   Matcher.setTarget(java.io.Readerint)
    See Also:   MatchResult
    See Also:   MatchResult.group(int)
    See Also:   MatchResult.start(int)
    See Also:   MatchResult.end(int)
    See Also:   MatchResult.length(int)
    See Also:   MatchResult.charAt(intint)
    See Also:   MatchResult.prefix
    See Also:   MatchResult.suffix



  • Field Summary
     intcounters
        
     intlookaheads
        
     intmemregs
        
     HashtablenamedGroupMap
        
     Termrootroot0
        
     StringstringRepr
        

    Constructor Summary
    protected  Pattern()
        
    public  Pattern(String regex)
         Compiles an expression with default flags.
    public  Pattern(String regex, String flags)
         Compiles a regular expression using Perl5-style flags. The flag string should consist of letters 'i','m','s','x','u','X'(the case is significant) and a hyphen. The meaning of letters:
    • i - case insensitivity, corresponds to REFLlags.IGNORE_CASE;
    • m - multiline treatment(BOLs and EOLs affect the '^' and '$'), corresponds to REFLlags.MULTILINE flag;
    • s - single line treatment('.' matches \r's and \n's),corresponds to REFLlags.DOTALL;
    • x - extended whitespace comments (spaces and eols in the expression are ignored), corresponds to REFLlags.IGNORE_SPACES.
    • u - predefined classes are regarded as belonging to Unicode, corresponds to REFLlags.UNICODE; this may yield some performance penalty.
    • X - compatibility with XML Schema, corresponds to REFLlags.XML_SCHEMA.
    regex the Perl5-compatible regular expression string.
    public  Pattern(String regex, int flags)
         Compiles a regular expression using REFlags. The flags parameter is a bitwise OR of the folloing values:
    • REFLlags.IGNORE_CASE - case insensitivity, corresponds to 'i' letter;
    • REFLlags.MULTILINE - multiline treatment(BOLs and EOLs affect the '^' and '$'), corresponds to 'm';
    • REFLlags.DOTALL - single line treatment('.' matches \r's and \n's),corresponds to 's';
    • REFLlags.IGNORE_SPACES - extended whitespace comments (spaces and eols in the expression are ignored), corresponds to 'x'.
    • REFLlags.UNICODE - predefined classes are regarded as belonging to Unicode, corresponds to 'u'; this may yield some performance penalty.
    • REFLlags.XML_SCHEMA - compatibility with XML Schema, corresponds to 'X'.
    regex the Perl5-compatible regular expression string.

    Method Summary
    protected  voidcompile(String regex, int flags)
        
    public  intgroupCount()
        
    public  IntegergroupId(String name)
         Get numeric id for a group name.
    public  Matchermatcher()
         Returns a targetless matcher.
    public  Matchermatcher(String s)
         Returns a matcher for a specified string.
    public  Matchermatcher(char[] data, int start, int end)
         Returns a matcher for a specified region.
    public  Matchermatcher(MatchResult res, int groupId)
         Returns a matcher for a match result (in a performance-friendly way).
    public  Matchermatcher(MatchResult res, String groupName)
         Just as above, yet with symbolic group name.
    public  Matchermatcher(Reader text, int length)
         Returns a matcher taking a text stream as target. Note that this is not a true POSIX-style stream matching, i.e.
    public  booleanmatches(String s)
        
    static  intparseFlags(String flags)
        
    static  intparseFlags(char[] data, int start, int len)
        
    public  Replacerreplacer(String expr)
         Returns a replacer of a pattern by specified perl-like expression.
    public  Replacerreplacer(Substitution model)
         Returns a replacer will substitute all occurences of a pattern through applying a user-defined substitution model.
    public  booleanstartsWith(String s)
        
    public  StringtoString()
        
    public  StringtoString_d()
         Returns a less or more readable representation of a bytecode for the pattern.
    public  RETokenizertokenizer(String text)
         Tokenizes a text by an occurences of the pattern.
    public  RETokenizertokenizer(char[] data, int off, int len)
         Tokenizes a specified region by an occurences of the pattern.
    public  RETokenizertokenizer(Reader in, int length)
         Tokenizes a specified region by an occurences of the pattern.

    Field Detail
    counters
    int counters(Code)



    lookaheads
    int lookaheads(Code)



    memregs
    int memregs(Code)



    namedGroupMap
    Hashtable namedGroupMap(Code)



    rootroot0
    Term rootroot0(Code)



    stringRepr
    String stringRepr(Code)




    Constructor Detail
    Pattern
    protected Pattern() throws PatternSyntaxException(Code)



    Pattern
    public Pattern(String regex) throws PatternSyntaxException(Code)
    Compiles an expression with default flags. regex the Perl5-compatible regular expression string.
    exception:
      PatternSyntaxException - if the argument doesn't correspond to perl5 regex syntax.
    See Also:   Pattern.Pattern(java.lang.Stringjava.lang.String)
    See Also:   Pattern.Pattern(java.lang.Stringint)



    Pattern
    public Pattern(String regex, String flags) throws PatternSyntaxException(Code)
    Compiles a regular expression using Perl5-style flags. The flag string should consist of letters 'i','m','s','x','u','X'(the case is significant) and a hyphen. The meaning of letters:
    • i - case insensitivity, corresponds to REFLlags.IGNORE_CASE;
    • m - multiline treatment(BOLs and EOLs affect the '^' and '$'), corresponds to REFLlags.MULTILINE flag;
    • s - single line treatment('.' matches \r's and \n's),corresponds to REFLlags.DOTALL;
    • x - extended whitespace comments (spaces and eols in the expression are ignored), corresponds to REFLlags.IGNORE_SPACES.
    • u - predefined classes are regarded as belonging to Unicode, corresponds to REFLlags.UNICODE; this may yield some performance penalty.
    • X - compatibility with XML Schema, corresponds to REFLlags.XML_SCHEMA.
    regex the Perl5-compatible regular expression string. flags the Perl5-compatible flags.
    exception:
      PatternSyntaxException - if the argument doesn't correspond to perl5 regex syntax.see REFlags



    Pattern
    public Pattern(String regex, int flags) throws PatternSyntaxException(Code)
    Compiles a regular expression using REFlags. The flags parameter is a bitwise OR of the folloing values:
    • REFLlags.IGNORE_CASE - case insensitivity, corresponds to 'i' letter;
    • REFLlags.MULTILINE - multiline treatment(BOLs and EOLs affect the '^' and '$'), corresponds to 'm';
    • REFLlags.DOTALL - single line treatment('.' matches \r's and \n's),corresponds to 's';
    • REFLlags.IGNORE_SPACES - extended whitespace comments (spaces and eols in the expression are ignored), corresponds to 'x'.
    • REFLlags.UNICODE - predefined classes are regarded as belonging to Unicode, corresponds to 'u'; this may yield some performance penalty.
    • REFLlags.XML_SCHEMA - compatibility with XML Schema, corresponds to 'X'.
    regex the Perl5-compatible regular expression string. flags the Perl5-compatible flags.
    exception:
      PatternSyntaxException - if the argument doesn't correspond to perl5 regex syntax.see REFlags




    Method Detail
    compile
    protected void compile(String regex, int flags) throws PatternSyntaxException(Code)



    groupCount
    public int groupCount()(Code)
    How many capturing groups this expression includes?



    groupId
    public Integer groupId(String name)(Code)
    Get numeric id for a group name. null if no such name found.
    See Also:   MatchResult.group(java.lang.String)
    See Also:   MatchResult.isCaptured(java.lang.String)



    matcher
    public Matcher matcher()(Code)
    Returns a targetless matcher. Don't forget to supply a target.



    matcher
    public Matcher matcher(String s)(Code)
    Returns a matcher for a specified string.



    matcher
    public Matcher matcher(char[] data, int start, int end)(Code)
    Returns a matcher for a specified region.



    matcher
    public Matcher matcher(MatchResult res, int groupId)(Code)
    Returns a matcher for a match result (in a performance-friendly way). groupId parameter specifies which group is a target.
    Parameters:
      groupId - which group is a target; either positive integer(group id), or one of MatchResult.MATCH,MatchResult.PREFIX,MatchResult.SUFFIX,MatchResult.TARGET.



    matcher
    public Matcher matcher(MatchResult res, String groupName)(Code)
    Just as above, yet with symbolic group name.
    exception:
      NullPointerException - if there is no group with such name



    matcher
    public Matcher matcher(Reader text, int length) throws IOException(Code)
    Returns a matcher taking a text stream as target. Note that this is not a true POSIX-style stream matching, i.e. the whole length of the text is preliminary read and stored in a char array.
    Parameters:
      text - a text stream
    Parameters:
      len - the length to read from a stream; if len is -1, the whole stream is read in.
    exception:
      IOException - indicates an IO problem
    exception:
      OutOfMemoryException - if a stream is too lengthy



    matches
    public boolean matches(String s)(Code)
    A shorthand for Pattern.matcher(String).matches().

    Parameters:
      s - the target true if the entire target matches the pattern
    See Also:   Matcher.matches
    See Also:   Matcher.matches(String)



    parseFlags
    static int parseFlags(String flags) throws PatternSyntaxException(Code)



    parseFlags
    static int parseFlags(char[] data, int start, int len) throws PatternSyntaxException(Code)



    replacer
    public Replacer replacer(String expr)(Code)
    Returns a replacer of a pattern by specified perl-like expression. Such replacer will substitute all occurences of a pattern by an evaluated expression ("$&" and "$0" will substitute by the whole match, "$1" will substitute by group#1, etc). Example:
     String text="The quick brown fox jumped over the lazy dog";
     Pattern word=new Pattern("\\w+");
     System.out.println(word.replacer("[$&]").replace(text));
     //prints "[The] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dog]"
     Pattern swap=new Pattern("(fox|dog)(.*?)(fox|dog)");
     System.out.println(swap.replacer("$3$2$1").replace(text));
     //prints "The quick brown dog jumped over the lazy fox"
     Pattern scramble=new Pattern("(\\w+)(.*?)(\\w+)");
     System.out.println(scramble.replacer("$3$2$1").replace(text));
     //prints "quick The fox brown over jumped lazy the dog"
     

    Parameters:
      expr - a perl-like expression, the "$&" and "${&}" standing for whole match, the "$N" and "${N}" standing for group#N, and "${Foo}" standing for named group Foo.
    See Also:   Replacer



    replacer
    public Replacer replacer(Substitution model)(Code)
    Returns a replacer will substitute all occurences of a pattern through applying a user-defined substitution model.
    Parameters:
      model - a Substitution object which is in charge for match substitution
    See Also:   Replacer



    startsWith
    public boolean startsWith(String s)(Code)
    A shorthand for Pattern.matcher(String).matchesPrefix().

    Parameters:
      s - the target true if the entire target matches the beginning of the pattern
    See Also:   Matcher.matchesPrefix



    toString
    public String toString()(Code)



    toString_d
    public String toString_d()(Code)
    Returns a less or more readable representation of a bytecode for the pattern.



    tokenizer
    public RETokenizer tokenizer(String text)(Code)
    Tokenizes a text by an occurences of the pattern. Note that a series of adjacent matches are regarded as a single separator. The same as new RETokenizer(Pattern,String);
    See Also:   RETokenizer
    See Also:   
    See Also:   RETokenizer.RETokenizer(jregex.Patternjava.lang.String)



    tokenizer
    public RETokenizer tokenizer(char[] data, int off, int len)(Code)
    Tokenizes a specified region by an occurences of the pattern. Note that a series of adjacent matches are regarded as a single separator. The same as new RETokenizer(Pattern,char[],int,int);
    See Also:   RETokenizer
    See Also:   
    See Also:   RETokenizer.RETokenizer(jregex.Patternchar[]intint)



    tokenizer
    public RETokenizer tokenizer(Reader in, int length) throws IOException(Code)
    Tokenizes a specified region by an occurences of the pattern. Note that a series of adjacent matches are regarded as a single separator. The same as new RETokenizer(Pattern,Reader,int);
    See Also:   RETokenizer
    See Also:   
    See Also:   RETokenizer.RETokenizer(jregex.Patternjava.io.Readerint)



    Methods inherited from java.lang.Object
    native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
    public boolean equals(Object obj)(Code)(Java Doc)
    protected void finalize() throws Throwable(Code)(Java Doc)
    final native public Class getClass()(Code)(Java Doc)
    native public int hashCode()(Code)(Java Doc)
    final native public void notify()(Code)(Java Doc)
    final native public void notifyAll()(Code)(Java Doc)
    public String toString()(Code)(Java Doc)
    final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
    final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
    final public void wait() throws InterruptedException(Code)(Java Doc)

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