org.mentaregex
Class Regex

java.lang.Object
  extended by org.mentaregex.Regex

public class Regex
extends Object

A perl-like regex support for Java.

Author:
Sergio Oliveira Jr. (sergio.oliveirajr@gmail.com)

Constructor Summary
Regex(String s, String pattern)
          Creates a new regex expression.
Regex(String s, String pattern, char escape)
          Creates a new regex expression.
 
Method Summary
static String escapeSlash(String s, String escapeChar)
          Escape a forward slash with the escape char provided.
 String[] match()
          Match and return what was matched.
static String[] match(String s, String pattern)
          Fast way to match.
static String[] match(String s, String pattern, char escapeChar)
          Fast way to match.
 boolean matches()
          Tell whether there is a match for this regex.
static boolean matches(String s, String pattern)
          Fast way to match.
static boolean matches(String s, String pattern, char escapeChar)
          Fast way to match.
static String sub(String s, String pattern)
          Fast way to substitute.
static String sub(String s, String pattern, char escapeChar)
          Fast way to substitute.
 String substitute()
          Substitute and return the new string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Regex

public Regex(String s,
             String pattern,
             char escape)
Creates a new regex expression.

Parameters:
s - The string to be matched or substituted
pattern - The regex pattern
escape - The escape char to use

Regex

public Regex(String s,
             String pattern)
Creates a new regex expression.

Parameters:
s - The string to be matched or substituted
pattern - The regex pattern
Method Detail

substitute

public String substitute()
Substitute and return the new string.

Returns:
The new string, in other words, the result of this regex substitution

matches

public boolean matches()
Tell whether there is a match for this regex.

Returns:
true if we have a match

match

public String[] match()
Match and return what was matched. That's for when you use regular expressions with parenthesis.

Returns:
What was matched or an empty array if nothing was matched

match

public static String[] match(String s,
                             String pattern)
Fast way to match.

Parameters:
s - The string to match
pattern - The regex pattern to match
Returns:
What was matched, if anything.

matches

public static boolean matches(String s,
                              String pattern)
Fast way to match.

Parameters:
s - The string to match
pattern - The regex pattern to match
Returns:
true if it was matched

match

public static String[] match(String s,
                             String pattern,
                             char escapeChar)
Fast way to match.

Parameters:
s - The string to match
pattern - The regex pattern to match
escapeChar - the escape char to use
Returns:
What was matched, if anything.

matches

public static boolean matches(String s,
                              String pattern,
                              char escapeChar)
Fast way to match.

Parameters:
s - The string to match
pattern - The regex pattern to match
escapeChar - the escape char to use
Returns:
true if it was matched

sub

public static String sub(String s,
                         String pattern)
Fast way to substitute.

Parameters:
s - The string to substitute
pattern - the pattern to match
Returns:
the new string

sub

public static String sub(String s,
                         String pattern,
                         char escapeChar)
Fast way to substitute.

Parameters:
s - The string to substitute
pattern - the pattern to match
escapeChar - the scape char to use
Returns:
the new string

escapeSlash

public static String escapeSlash(String s,
                                 String escapeChar)
Escape a forward slash with the escape char provided. Great for directories for example.

Parameters:
s - The string to change
escapeChar - the escape char to use
Returns:
the new string with the slashed escaped with the given escape char


Copyright © 2011. All Rights Reserved.