Question about Regular Expressions, please help!

I have created an app which reads files and extracts certain data using regular expressions in JDK1.4 using Pattern and Matcher classes.
However it needs to run on JDK1.2.2 (dont ask). The regular expression classes are not available in 1.2.2 (the Pattern and Matcher class) so i am looking for something similiar which i can use?
I need something that loops through all the matches found in the file like how Matcher works i.e.
while (matcher.find())
// do this
Help!

http://jakarta.apache.org/regexp/

Similar Messages

  • Regular Expressions, please help.

    Hello everyone.
    Can I get a Java Regular Expression to match with a word of the following language...
    Start --> Expression;
    Expression --> [0-9]+;
    Expression --> Expression * Expression;
    So the regexp should match with words like:
    4;
    4664;
    4 * 763;
    5 * 4534 * 23534;
    04 * 002 * 1 * 10 * ...
    I would be very happy, if anyone could help.

    I dont think that I need to learn anything more.
    I am sure it is not possible to make, what I want.
    I want to build a compiler.
    I just finished the abstract syntax of my language. Now I need a possibility to compile the concrete syntax of my language to the abstract one.
    But I think, it is not possible with regular expressions.
    Cause I need possibility to match a syntax of type chomsky 2.
    I think regular expressions only match chomsky 3 languages.
    But the "Backtracking"-mechanism of Java RegExp could do this.
    I am not sure with this.
    If you have any ideas please post.

  • Basic question about regular expressions

    Hello,
    I am a beginner to regular expressions. I want to rewrite the following expression:
    public static final String REGULAR_EXP_SOFTWARE_PART_NUMBER = "([0-9]{7}[a-z]{1})(\\-{1})([a-z]{1})";I want THIS match
    (\\-{1})to occur EITHER if a hyphen is encountered OR if a space is encountered (instead of just the hyphen).
    How do I rewrite this?
    Thanks in advance,
    Julien.

    Hello and thanks for your feedback,
    I have created a small class as follows:
    package regExpr;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    * @author Martin
    public class RegExprTest {
         private static String stringToBeParsed = "3800157w-e26";
         public static void main(String[] args) {
              Pattern pattern = Pattern.compile("" +
                        "([0-9]{7})" +
                        "([a-z]{1})" +
                        "(( |-){1})" +
                        "([a-z]{1})" +
                        "([0-9]{2})" +
              Matcher matcher = pattern.matcher(stringToBeParsed);
              while(matcher.find()){
                   System.out.println(matcher.group(1));
                   System.out.println(matcher.group(2));
                   System.out.println(matcher.group(3));
                   System.out.println(matcher.group(4));
                   System.out.println(matcher.group(5));
                   System.out.println(matcher.group(6));
    }the class is trying tobreak down the following string "3800157w-e26" as follows:
    3800157(seven digits)
    w(one letter)
    -(hyphen)
    e(one letter)
    26(two digits)
    Oddly enough the output of the class is as follows:
    3800157
    w
    e
    26
    I have to call the group method six times and I get two hyphens!
    Can anyone help?
    Thanks in advance,
    Julien

  • Simple question about regular expressions

    Hi,
    Using Java's regular expression syntax, what is the correct pattern string to detect strings like the following :-
    AnnnnnA
    where A = a single (fixed) alphabetic character and
    n = at least one but possibly many digits [0-9].
    Example strings to be searched :-
    A45A (this should match)
    A3A (this should match)
    A3446655577A (this should match)
    A hello world A (this should NOT match as no digits are present between the A's).
    Thanks.

    A least one digit "A.*\\d.*A"
    Only digits "A\\d+A"

  • One question about Regular Expression!!!

    I need to creat such a regular expression to match the format "[ ][ ][ ]".
    For example, there is a context,
    (1), " The project manager defines [1][0.400][+goals] for iterations."
    Suppose that there are some spaces or "\n" characters in this way,
    (2), " The project manager defines [    1 ] [  0.400   ]
    [   +goals] for iterations."
    If the pattern match the format succefully, (2) strings should be replaced by (1)strings, in order words, the format of (1) is what I need finally,
    I had ever tried creating a regular expression likes \\[([^\n\s]]+)\\]\\[([^\n\s]]+)\\]\\[([^\n\s]]+)\\] , but it does not work well!
    DO YOU HOW TO IMPLEMENT IT IN JAVA?
    Thanks for your any reply!

    What I really need is that, via the regular
    expression, all the spaces and \n characters in
    square brackets [ and ], ] and [, will be thrown
    away.
    For example,
    Original:
    1) "The project manager defines [   1  ] [
    0.400 ]
    [   +goals] for iterations with the support"
    After matching:
    2) "The project manager defines [1][0.400][ [+goals]
    for iterations with the support"
    String 2) is what I need finally!
    Thanks for your any reply!Well I gave you the answer to that one already :-)
    If you need to preserve the spaces in between words use this one. I'm sure there's a better way to do it, I'm no RegEx master.
        public static void main(String[] args)
            String s = "[ 1 ] [ 0.400 ]\n[ +go als]";
            System.out.println( "Before: " + s );
            System.out.println( "\n\n" );
            s = s.replaceAll( "\\[\\s+", "[" );
            s = s.replaceAll( "\\s+\\]", "]" );
            s = s.replaceAll( "\\]\\s+\\[", "][" );
            System.out.println( "After: " + s );
        }

  • Beginner question about Regular expression

    Hi all !
    I'd like to use a regular expression to parse a string like this:
    *<ID>4</ID><GROUP>5</GROUP>....*
    So for example to retrieve the ID I have built the following regular expression:
    Pattern p = Pattern.compile("<ID>(.*?)</ID>");  
    Matcher m = p.matcher(handle);    
    if (m.find()) {
          System.out.println("->"+m.group());     
    } else {
    System.out.println("No match!");   
    }The function m.group returns "<ID>4</ID>" but I want just the value (4) between the tag. Is there
    a way to get it ?
    thanks a lot
    mark

    fmarchioniscreen wrote:
    thank you very much, that's exactly what I needed.
    But it looks like you're parsing some XML like data: probably better to use a proper parser on it. Well it's a very short string containing XML tags. it's used in a marginal area of the application so I prefer just using a regular expression to fetch the values
    thanks again
    MarkYou could use XPath to get the value.

  • An additional question about regular expressions with String.matches

    does the String.matches() method match expressions when some substring of the String matches, or does it have to match the entire String? So, if i have the String "123ABC", and i ask to match "1 or more letters" will it fail because there are non-letters in the String, but then pass if i add "1 or more letters AND 1 or more digits"? so, in the latter every character in the String is accounted for in the search, as opposed to the first. Is that correct, or are there ways to JUST match some substring in the String instead of the whole thing? i WILL make some examples too... but does that make sense?

    It has to match the whole String. Use Matcher.find() to match on just a sub-string()

  • Question about Regular Expressions

    Hi averyone!
    Could any one help me to create RegEx for string: <object>
    Thanks!
    Kind Regards, Dmitry.

    "<object>"

  • A question about arrays. Please Help

    Ok here is my question lets say i have a multie varible array such as
    int[][] thisList = new int[3][64];And I have a number of other arrays that are single variable arrays, and which have data stored in them.
    List1[64]
    List2[64]
    List3[64]is there a way i can store all these three list in the multie varible array?
    for example i know i can do this, > Correct me if i am wrong
    List1 = List2; where List1 one now contains all the elements that List2 has.
    but is there a way i can
    us the same format with a multie varible array, to store all three list in it.
    such as thisList[1][] = List1; thisList[2][] = List2[]; Thanks

    for example i know i can do this, > Correct me if i
    am wrong
    List1 = List2; where List1 one now
    contains all the elements that List2 has.There will be one array. Both the List1 and List2 reference variables will point to that same array.
    (By the way, convention in Java is for variables to start with lowercase.)
    >
    but is there a way i can
    us the same format with a multie varible array, to
    store all three list in it.
    such as thisList[1][] = List1; thisList[2][] =
    List2[];
    You can do thisList[1] = List1 if thisList is an int[][] and List1 is an int[]. However, that will not copy any ints. It will just do the same as the above--cause the reference thisList[1] to point to the same array object as List1 does.
    If you want to copy values from one array to another, use System.arraycopy.

  • Simple question about regular expression

    Hi
    I have a little problem with
    select regexp_substr('123 Mapla Avenue','[a-z]') my_test from dual;
    answer: M
    I excecute this query in SQLPlus and SQL Developer result is this same.
    select regexp_substr('123 Mapla Avenue','[M]') my_test from dual;
    answer: M
    select regexp_substr('123 Mapla Avenue','[a]') my_test from dual;
    answer: a
    I used oracle 10g
    Thanks for your help

    hm wrote:
    In the oracle documentation of regexp_substr you can find:Do not confuse pattern and sort. Pattern [a-z] means any lowercase letter. REGEXP_SUBSTR parameter match_param value i tells REGEXP to treat uppercase letters same as lowercase letters and vice versa. And setting NLS_SORT can do the same. As you can see it is not that straight-forward. To make it transparent use exact pattern you need. In this particular case use:
    select regexp_substr('123 Mapla Avenue','[[:alpha:]]') my_test from dual;where class [:alpha:] is POSIX predefined class of all letters (regardless of case). This way you are not dependent of client side settings like NLS_SORT and the above will always return first letter within a string. If you want first uppercase letter use:
    select regexp_substr('123 Mapla Avenue','[[:upper:]]') my_test from dual;Or, for first lowercase letter:
    SQL> alter session set nls_sort=binary;
    Session altered.
    SQL> select regexp_substr('123 Mapla Avenue','[a-z]') my_test from dual;
    M
    a
    SQL> select regexp_substr('123 Mapla Avenue','[[:lower:]]') my_test from dual;
    M
    a
    SQL> alter session set nls_sort=binary_ci;
    Session altered.
    SQL> select regexp_substr('123 Mapla Avenue','[a-z]') my_test from dual;
    M
    M
    SQL> select regexp_substr('123 Mapla Avenue','[[:lower:]]') my_test from dual;
    M
    a
    SQL> SY.

  • Question about lost iPod - Please help me out!!

    My iPod was stolen and is there anyway to relocate it if it connect to someone's computer? Could Apple track it down? And I am not sure whether I have registered my iPod online. Is there anyway to check??

    Apple have no process in place to either report or track stolen iPods. All you can do is report the theft to the Police together with it's serial number, and if your iPod was registered with Apple when you first got it, they will assist the Police in returning it to you should it ever be recovered.

  • A question about NAST_CREATE_MESSAGE_OBJECT?Please help

    Hello:
       We are now using function:NAST_CREATE_MESSAGE_OBJECT to create an EDI message into NAST in our program.But there is alwasys the following message when NAST_CREATE_MESSAGE_OBJECT is called and then this function will fail.Could you tell me how I can fix this issue?
    Function module SO_NAME_CONVERT with return code
                                                  7
    completed
    No message title for condition type E in
    maintained
    Thanks

    Launch Terminal.app
    Type cd followed by a space. Do not hit return key just yet.
    In Finder, navigate to folder containing the files you want to blow away.
    Drag and drop that folder (in the finder) into the Terminal.app window. It'll autofill the path to the directory containing the files you're wanting to blow away. Now hit the return key.
    You could type ls (that's a lower-case ell) and see the directory listing of all the files in your current directory. Probably a good idea to do just to doublecheck that you really are in the directory that you want to blow away all these files from.
    Now do what Greg said.
    Don't get impatient because Terminal is just sitting there and you're not getting an immediate command prompt. It'll take a while to blow away 9000 files.
    For entertainment, instead of rm *" copy"* use rm -v *" copy"* so you can watch all 9000 file names be printed in your terminal window as they are being deleted.
    Will it work? Oh yes .... irreversibly (if it doesn't, that's coz' there are some file ownership and/or file permission issues that need to be looked at, but assuming those are "compatible" with your current Terminal user environment, those guys'll be toast. Any file that's in the working directory where you are in Terminal that has the five characters " copy" in its filename will be history.
    The assumption in Greg's command is that all the files you want to blow away all reside in the one directory that you have navigated to.

  • A question about firing event, please help

    I would like to know how to fire an event in the following situation:
    public class FireAnEvent
             public static void main()
                   char c=(char)System.in.read())s;
                   String source="I'm the source";
                   if(c!="a")
                          fireActionEvent(new ActionEvent(source,1,null);
    }the above code won't work obviously, but what should i do to make it work, or is it possible to fire in this situation?
    thanks in advance;
    Message was edited by:
    fandebiao

    My personal favourite way to quickly fire custom events is through using enums in the XXXEvent class. That way checking which event was called is easy, and it's also typesafe.
    fireXXXEvent(XXXEvent.ID.MY_ID, "...");
      private List<XXXListener> listeners = new LinkedList<XXXListener>();
      private synchronized void fireXXXEvent(XXXEvent.ID eventID, String args) {
        XXXEvent event = new XXXEvent(this, eventID);
        event.setupOtherStuff(args);
        for (XXXListener l : listeners) {
          switch (eventID) {
            case MY_ID:
              l.xxxAction(event);
              break;
            case MY_OTHER_ID:
              l.xxxOtherAction(event);
              break;
            default:
              break;
      public synchronized void addXXXListener(XXXListener l) { listeners.add(l); }
      public synchronized void removeXXXListener(XXXListener l) { listeners.remove(l); }

  • I can't remember answers from security questions... Please help me....apple support don't answer.(((

    I can't remember answers from security questions... Please help me....apple support don't answer.(((

    1. See my User Tip for some help: Some Solutions for Resetting
        Forgotten Security Questions: Apple Support Communities.
    2. Here are two different but direct methods:
        a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
        b. Call Apple Support in your country: Customer Service: Contacting Apple for
            support and service.
    3. For other queries about Apple ID see Frequently asked questions about Apple ID.
    4. Rescue email address and how to reset Apple ID security questions
    5. For online assistance use Apple - Support - Express Lane

  • Off Topic: Books about Regular Expression

    Hi
    Somebody can to indicate books about Regular Expression in Oracle ?
    Thanks

    Regex tag of Blog of Volder.
    http://volder-notes.blogspot.com/search/label/Regular%20Expressions
    This entry mentions my regex solution :-)
    http://volder-notes.blogspot.com/2007/10/removing-duplicate-elements-from-string.html
    By the way
    My regex homepage mentions regex problems of perl like regex (regex of EmEditor).
    http://www.geocities.jp/oraclesqlpuzzle/regex/
    example questions (written by Japanese language)
    http://www.geocities.jp/oraclesqlpuzzle/regex/regex-2-1.html
    http://www.geocities.jp/oraclesqlpuzzle/regex/regex-3-5.html
    http://www.geocities.jp/oraclesqlpuzzle/regex/regex-4-4.html

Maybe you are looking for

  • Treo 680 Calendar

    Help! It's January 1 and my AT&T Treo 680 that I got in June 2007 has suddenly decided to not show some or all events.  If I tap and drag on the screen where an event has been added, I then see them, but it also adds an uncategorized event.  In month

  • Instance does not open, because of corrupted datafile

    Hi I am running 10gR2. For a test I have corrupted the header of an test datafile of a non system tablespace when instance was closed. Now when I started the instance it does not open with an alert entry Errors in file c:\oracle\oracle\product\10.2.0

  • Default Values in an ABAP selection criteria

    Hi SAP Experts, I've created a info set(SQ02) and a query(SQ01) to generate a report on purchase orders. I want to default the purchase order type to NB in the selection screen(In order to retrieve the purchase orders with type NB only) Can someone p

  • Odd Tab Behavior in InDesign CS5

    I've used CS2 for quite a few years now, but decided it was time to upgrade to CS5. Doing so in the middle of a big book layout project was PROBABLY not the best idea. Essentially, I have laid out a document in this fashion: The headings are set 0.0"

  • List of Components used in Production Order

    Hi , I want to report in which I want to pull out all the componets in the production order.I dont want explode the BOM for the day as many components might have been manually added in the productio order and it may not be present in BOM. is there an