Solved

Regular Expressions and Strings

Posted on 2002-04-17
7
173 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 145
Problem to start Neon 20 86
recursion example 16 111
how to add new optional parameter to JSP 1 29
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now