Solved

Regular Expressions and Strings

Posted on 2002-04-17
7
177 Views
Last Modified: 2010-08-05
Basically I have a program with two text edit boxes and a button on it.  The user can enter a piece of text into the first edit box and a regular expression into the second edit box.

When the user presses the button I want it to process the regular expression against the text that the user entered.  

Is there any way to implement this using Java ?

I would be grateful for all advice offered regarding this.

Thanks in advance

John Clarke
0
Comment
Question by:johnclarke
7 Comments
 
LVL 2

Expert Comment

by:Andrey_Kulik
ID: 6947287
Hi
in JDK 1.4  see package java.util.regex.*
in additional see:
http://jakarta.apache.org/regexp/index.html

0
 
LVL 2

Expert Comment

by:CSuvendra
ID: 6947294
Implementation of Regular Expressions under GNU license

http://www.cacas.org/java/gnu/regexp/
0
 
LVL 9

Accepted Solution

by:
Venci75 earned 50 total points
ID: 6947300
java 1.4 have classes for processing regular expressions

try this sample code:
import java.util.regex.*;
...
System.out.println("" + Pattern.compile("[0-9]").matcher("1").matches());
System.out.println("" + Pattern.compile("[0-9]").matcher("d").matches());
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 1

Expert Comment

by:Moondancer
ID: 6956327
Please click the link below to manage your open and locked questions here to provide feedback and closures for those who have helped you.
http://www.experts-exchange.com/jsp/memberProfile.jsp?mbr=johnclarke&showQHistory=true&qAskBegin=11&qAskEnd=89#1
Thanks,
Moondancer - EE Moderator
0
 

Expert Comment

by:master_p
ID: 6968390
See http://jakarta.apache.org/regexp/index.html

import org.apache.oro.text.regex.*;

public class Tester
{
    public boolean matches(
        String aRegularExpression,
        String aString)
    throws Exception
    {
        Perl5Compiler myCompiler = new Perl5Compiler();
       
        Pattern myPattern = myCompiler.compile(
                    aRegularExpression,
                    Perl5Compiler.DEFAULT_MASK);

        PatternMatcher myMatcher = new Perl5Matcher();

        return myMatcher.matches(aString, myPattern);
    }

    public static void main(String anArg[])
    throws Exception
    {
        Tester myTester = new Tester();
        System.out.println(myTester.matches(anArg[0], anArg[1]));
    }
}
0
 

Author Comment

by:johnclarke
ID: 6970158
Although it is a good answer I prefer to use the native classes provided with JDK.  Sorry.

John
0
 

Author Comment

by:johnclarke
ID: 6970159
Thanks for pointing me to where I wanted to go.

John
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question