[plug] [Somewhat OT] Regexp guru?

Kirk Turner mlist at wagoonline.com
Tue Dec 17 17:52:54 WST 2002


Heyas,

This isn't strictly a linux thing, but figured since regexp is used 
widely in linux someone might have more of a clue
than I do :-)

The problem is this:
I'm using Java 1.4's Pattern/String split function which takes a regexp 
to determine what string is used to split another string into an array 
of tokens. e.g:
    if I have a string
        this is just a simple test
    and I split it with a regexp " " (a blank space) it will return an 
array as follows:
        this
        is
        just
        a
        simple
        test

Anyway this isn't a problem, but what I need to do is to distinguish 
between spaces and spaces that are between quotation marks. e.g:
    if I have a string
        this is just a "simple little" test
    the regexp should return only the spaces not between "" so the array gives
        this
        is
        just
        a
        "simple little"
        test


With or without the quotation marks is fine.

Any help or suggestions (or telling me its not at all possible) would be 
great!

The test java program I've been using is as follows (NOTE: the split 
function only exists sinec java 1.4)

public static void main (String[] args) {
   String[] st = "This \"is a\" \"simple little\" test!".split(args[0]);
   for (int i = 0; i < st.length; i++) {
     System.out.println(st[i]);
    }
}




Thanks,

Kirk Turner
-----
Software Engineer/System Admin.
WA Go Online Pty. Ltd.
http://www.wagoonline.com





More information about the plug mailing list