Solved

Regular Expressions and Strings

Posted on 2002-04-17
7
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

752 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