Solved

Regular Expressions and Strings

Posted on 2002-04-17
7
169 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 71
mapAB Challlenge 35 85
Systems talking to each other 5 108
Java passing arguments (type error) 2 33
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…
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…
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 …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

707 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

18 Experts available now in Live!

Get 1:1 Help Now