Command line style regular expression string parser

Hi people,
I am currently working on a program where I need to parse a file (or any input stream) line by line. I then need to parse every line for arguments. Each line is formatted similar to how arguments are passed to the command line. The regular expression needs to split every line by any encountered whitespace, but needs to be able to retain any whitespace within double quotes (i.e. "some spaced text here"). Arguments can be numbers, booleans and (quoted) strings. Quoted strings must also be able to have escaped quotes in it (as below). The quotes for the quoted string (the outer ones, obviously not the escaped ones) do not necessarily have to be retained.
An example input line:
arg1 arg2 "arg 3" "arg 4" 987 arg6 "arg \"arg \"arg 7"
Desired example output:
arg1
arg2
arg 3
arg 4
987
arg6
arg "arg "arg 7
After the input line has been split up the program will handle any parsing (i.e. numbers, booleans, etc.). The program currently uses a simple for loop to iterate over all characters in the line and splits it up appropriately by checking every character. However, if this can be done automatically by using a regular expression passed to String.split() (or with some use of the regex package), it would remove quite a bit of redunant code and make the program that much more maintainable.
I do not have much experience with regular expressions since I have never really had the need to use them, but if they can work in this case it would be great.
Thanks in advance for any help.

Almost any parsing problem can be solved if you throw a big enough and ugly enough regex at it, or so I'm told.
I think what you are doing is also amenable to java.io.StreamTokenizer:
import java.io.*;
import static java.io.StreamTokenizer.*;
public class StreamTokenizerExample {
    public static void main(String[] args) throws IOException {
        StringReader input = new StringReader("arg1 arg2 \"arg 3\" \"arg 4\" 987 arg6 \"arg \\\"arg\\\" arg 7\"\nnextline");
        StreamTokenizer in = new StreamTokenizer(input);
        in.eolIsSignificant(true);
        for(int ttype; (ttype = in.nextToken()) != TT_EOF; ) {
            switch (ttype) {
                case TT_WORD:
                    System.out.println("String[" + in.sval + "]");
                    break;
                case TT_NUMBER:
                    System.out.println("number[" + in.nval + "]");
                    break;
                case TT_EOL:
                    System.out.println("[EOL]");
                    break;
                case '"':
                    System.out.println("quoted[" + in.sval + "]");
                    break;
                default:
                    System.out.println("unexpected " + ttype);
{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Need advice on negating a whole string line with regular expression

    Hi All,
    I am not able to ignore / get rid of the following line even though my Java 6 (Windows XP) String Pattern matching has not taken cater for it:
    *% Cleared: 61%*
    Below is the existing Java String Pattern matching in the simple program:
    Pattern pattern = Pattern.compile("(^.*[A-Z][a-z]*){1,2} \\d{0,4}/?\\d{0,4} ([A-Z][a-z]*){1,2} St|Rd|Av|Sq|Cl|Pl|Cr|Gr|Dr|Hwy|Pde|Wy|La \\d br [h|u|t] \\$\\d+,\\d+|\\$\\d*\\,\\d+,\\d+ ([A-Z][a-z]*){1,}.*$");This pattern is working for valid strings.
    The following pattern has included "^(?!.*\.\.).*$" into the existing one but had no luck still:
    Pattern pattern = Pattern.compile("^(?!.*\.\.).*$|((^.*[A-Z][a-z]*){1,2} \\d{0,4}/?\\d{0,4} ([A-Z][a-z]*){1,2} St|Rd|Av|Sq|Cl|Pl|Cr|Gr|Dr|Hwy|Pde|Wy|La \\d br [h|u|t] \\$\\d+,\\d+|\\$\\d*\\,\\d+,\\d+ ([A-Z][a-z]*){1,}.*$)");This picked up other rubbish including "*% Cleared: 61%*".
    I am looking for a single regular expression that applies to the whole line.
    I am quite new to regular expression but has read through Regular Expressions Cookbook (Oreilly - 2009) and is still not familiar with advance functions such as lookahead / lookbehind...
    Your assistance would be appreciated.
    Thanks,
    Jack

    Hi Winston,
    I am still digesting the material from the regular expression book and will take sometime to become proficient with it.
    It seems that using groupCount() to eliminate the unwanted text does not work in this case, since all the lines returned the same value. Ie 3 posted earlier. This may be because the patterns are complex and only a few were grouped together. Otherwise, could you provide an example using the string posted as opposed to a hyperthetic one. In the meantime, at least one solution have been found by defining an additional special pattern “\\A[^%].*\\Z”, before combining / intersecting both existing and the new special pattern to get the best of both world. Another approach that should also work is to evaluate the size of String.split() and only accept those lines with a minimum number of tokens.
    Anyhow, I have come a crossed another minor stumbling block in the mean time with the following line, where some hidden characters is preventing the existing pattern from reading it:
    o;?Mervan Bay 40 Boyde St 7 br t $250,000 X West Park AE
    Below is the existing regular expression that works for other lines with the same pattern but not for special hidden characters such as “o;?”:
    \\A([A-Z][a-z]*){1,2} [0-9]{0,4}/?[0-9]{0,4}-?[0-9]{0,4} ([A-Z][a-z]*){1,2} St|Rd|Av|Sq|Cl|Pl|Cr|Gr|Dr|Hwy|Pde|Wy|La [0-9] br [h|u|t] \\$\\d+,\\d+|\\$\\d*\\,\\d+,\\d+ ([A-Z][a-z]*){1,}\\ZIs it possible to come up with a regular expression to ignore them so that this line could be picked up? Would also like to know whether I could combine both the special pattern “\\A[^%].*\\Z” with existing one as opposed to using 2 separate patterns altogether?
    Many thanks,
    Jack

  • Regular expressions to parse arithmetic expression

    Hello,
    I would like to parse arithmetic expressions like the following
    "5.2 + cos($PI/2) * -5"where valid expression entities are numbers, operations, variables and paranthesis. Until now I have figured out some regular expressions to match every type of entities that I need, and combine them into one big regex supplied to a pattern and matcher. I will paste some code now to see what I wrote:
    public class RegexTest {
        /** A regular expression matching numeric expressions (floating point numbers) */
        private static final String REGEX_NUMERIC = "(-?[0-9]+([0-9]*|[\\.]?[0-9]+))";
        /** A regular expression matching a valid variable name */
        private static final String REGEX_VARIABLE = "(\\$[a-zA-Z][a-zA-Z0-9]*)";
        /** A regular expression matching a valid operation string */
        public static final String REGEX_OPERATION = "(([a-zA-Z][a-zA-Z0-9]+)|([\\*\\/\\+\\-\\|\\?\\:\\@\\&\\^<>'`=%#]{1,2}))";
        /** A regular expression matching a valid paranthesis */
        private static final String REGEX_PARANTHESIS = "([\\(\\)])";
        public static void main(String[] args) {
            String s = "5.2 + cos($PI/2) * -5".replaceAll(" ", "");
            Pattern p = Pattern.compile(REGEX_OPERATION + "|" + REGEX_NUMERIC + "|" + REGEX_VARIABLE + "|" + REGEX_PARANTHESIS);
            Matcher m = p.matcher(s);
            while (m.find()) {
                System.out.println(m.group());
    }The output is
    5
    2
    +
    cos
    $PI
    2
    5There are a few problems:
    1. It splits "5.2" into "5" and "2" instead of keeping it together (so there might pe a problem with REGEX_NUMERIC although "5.2".matches(REGEX_NUMERIC) returns true)
    2. It interprets "... * -5" as the operation " *- " and the number "5" instead of " * " and "-5".
    Any solution to solve these 2 problems are greately appreciated. Thank you in advance.
    Radu Cosmin.

    cosminr wrote:
    So, I've written some concludent examples and the output after parsing (separated by " , " ):
    String e1 = "abs(-5) + -3";
    // output now: abs , ( , - , 5 , ) , + , - , 3 ,
    // should be:  abs , ( , -5 , ) , + , - , 3 , (Notice the -5)
    I presume that should also be "-3" instead of ["-", "3"].
    String e2 = "sqrt(abs($x=1 + -10))";
    // output now: sqrt , ( , abs , ( , $x , = , 1 , + , - , 10 , ) , ) ,
    // should be:  sqrt , ( , abs , ( , $x , = , 1 , + , -10 , ) , ) ,   (Notice the -10)
    String e3 = "$e * -1 + (2 - sqrt(4))";
    // output now: $e , * , - , 1 , + , ( , 2 , - , sqrt , ( , 4 , ) , ) ,
    // should be:  $e , * , -1 , + , ( , 2 , - , sqrt , ( , 4 , ) , ) ,
    String e4 = "sin($PI/4) - 3";
    // output now: sin , ( , $PI , / , 4 , ) , - , 3 , (This one is correct)
    String e5 = "sin($PI/4) - -3 - (-4)";
    // output now: sin , ( , $PI , / , 4 , ) , - , - , 3 , - , ( , - , 4 , ) ,
    // should be:  sin , ( , $PI , / , 4 , ) , - , -3 , - , ( , -4 , ) ,  (Notice -3 and -4)I hope they are relevant, If not I will supply some more.I made a small change to REGEX_NUMERIC and also put REGEX_NUMERIC at the start of the "complete pattern" when the Matcher is created:
    import java.util.regex.*;
    class Test {
        private static final String REGEX_NUMERIC = "(((?<=[-+*/(])|(?<=^))-)?\\d+(\\.\\d+)?";
        private static final String REGEX_VARIABLE = "\\$[a-zA-Z][a-zA-Z0-9]*";
        public static final String REGEX_OPERATION = "[a-zA-Z][a-zA-Z0-9]+|[-*/+|?:@&^<>'`=%#]";
        private static final String REGEX_PARANTHESIS = "[()]";
        public static void main(String[] args) {
            String[] tests = {
                "abs(-5) + -3",
                "sqrt(abs($x=1 + -10))",
                "$e * -1 + (2 - sqrt(4))",
                "sin($PI/4) - 3",
                "sin($PI/4) - -3 - (-4)",
                "-2-4" // minus sign at the start of the expression
            Pattern p = Pattern.compile(REGEX_NUMERIC + "|" + REGEX_OPERATION + "|" + REGEX_VARIABLE + "|" + REGEX_PARANTHESIS);
            for(String s: tests) {
                s = s.replaceAll("\\s", "");
                Matcher m = p.matcher(s);
                System.out.printf("%-21s-->", s);
                while (m.find()) {
                    System.out.printf("%6s", m.group());
                System.out.println();
    }Note that since Java's regex engine does not support "variable length look behinds", you will need to remove the white spaces from your expression, otherwise REGEX_NUMERIC will go wrong if a String looks like this:
    "1 - - 1"Good luck!

  • Match beginning of line with Regular Expression

    I'm confused about dreamweaver's treatment of the characters
    ^ and $ (beginning of line, end of line) in regex searches. It
    seems that these characters match the beginning of the file, not
    the beginning of the various lines in the file. I would expect it
    to work the other way around. A search like:
    (^.)
    should match every line in the file, so that a find/replace
    could be performed at the beginning of each line, like this:
    HELLO$1
    which would add 'HELLO' at the start of each line in the
    file.
    Instead, this action only matches the first character of the
    file, sticks 'HELLO' in front of it, and then quits (or moves on to
    the next file). The endline character $ behaves in a similar
    fashion, matching only the end of the file, not the end of each
    line.
    I've searched, and all the literature about regular
    expressions in dreamweaver seems to indicate that I'm expecting the
    correct behavior:
    www.adobe.com/devnet/dreamweaver/articles/regular_expressions_03.html
    quote:
    ^ Beginning of input or line ^T matches "T" in "This good
    earth" but not in "Uncle Tom's Cabin"
    $ End of input or line h$ matches "h" in "teach" but not in
    "teacher"
    Thanks for any insight, folks.

    Hi Winston,
    I am still digesting the material from the regular expression book and will take sometime to become proficient with it.
    It seems that using groupCount() to eliminate the unwanted text does not work in this case, since all the lines returned the same value. Ie 3 posted earlier. This may be because the patterns are complex and only a few were grouped together. Otherwise, could you provide an example using the string posted as opposed to a hyperthetic one. In the meantime, at least one solution have been found by defining an additional special pattern “\\A[^%].*\\Z”, before combining / intersecting both existing and the new special pattern to get the best of both world. Another approach that should also work is to evaluate the size of String.split() and only accept those lines with a minimum number of tokens.
    Anyhow, I have come a crossed another minor stumbling block in the mean time with the following line, where some hidden characters is preventing the existing pattern from reading it:
    o;?Mervan Bay 40 Boyde St 7 br t $250,000 X West Park AE
    Below is the existing regular expression that works for other lines with the same pattern but not for special hidden characters such as “o;?”:
    \\A([A-Z][a-z]*){1,2} [0-9]{0,4}/?[0-9]{0,4}-?[0-9]{0,4} ([A-Z][a-z]*){1,2} St|Rd|Av|Sq|Cl|Pl|Cr|Gr|Dr|Hwy|Pde|Wy|La [0-9] br [h|u|t] \\$\\d+,\\d+|\\$\\d*\\,\\d+,\\d+ ([A-Z][a-z]*){1,}\\ZIs it possible to come up with a regular expression to ignore them so that this line could be picked up? Would also like to know whether I could combine both the special pattern “\\A[^%].*\\Z” with existing one as opposed to using 2 separate patterns altogether?
    Many thanks,
    Jack

  • Regular expression html parsing

    I have following sample html
    <html><body>
    First Name<input type="text" class="txtField" name="txtFirstName"\>
    Last name
    <input type="text" name="txtLastName"\>
    Address <textarea name="address" rows="10">Here goes address</textarea>
    <input type="button" name="btnSubmit" class="button"\>
    </body></html>
    I m trying to build a regular expression in such a way that, the expression should find a list of tags based on the set of names available.
    for e.g. I have string array as String names[] = {"txtLastName", "address"}
    using above array, the expression must find tag in above html.
    So in above case the output should be
    <input type="text" name="txtLastName"\>
    <textarea name="address" rows="10">
    Can somebody suggest how this expression should be build?

    Hi,
    As from your question,
    I got that you want to parse the HTML file and from the names in the array you want to
    get the code those controls.
    In that case I think you can use
    Find the string
    1.which starts with '<' and ends with '>'
    2.It must contains your work("txtLastName", "address"....) in double quotes(statring & ending) excatly one.
    Best,
    Ronak

  • Regular expressions string length

    Hi
    New to regular expressions and trying to create an expressions that will test if a string does not contain any number and is less than 20 characters long! This works for determining if it has any numbers in it, but how do I specify that it can be between 1 and 20 characters in length? The + means >1 but how do I cap it?
    Pattern p = Pattern.compile("[a-zA-Z]+");
             Matcher m = p.matcher(value);
             if (m.matches()) System.out.println("yes");I have tried [a-zA-Z]+{5} but that doesn't work. Any handy hints... can't find much stuff that is applicable via google, frustrating.
    Thanks.

    Looce wrote:
    Pattern p = Pattern.compile("[a-zA-Z]{1,20}"); // repetition totally replaces +, doesn't coexist with it
    Matcher m = p.matcher(value);
    if (m.matches()) System.out.println("yes");
    Note that the following code can be shortened by doing:
    if(value.matches("[a-zA-Z]{1,20}")) { /* ... */ }

  • Regular Expression string

    Hi,
    I'm looking for a single regular expression.
    E.g. My string is 'get data for comparison'. So when using regular expression as \Wcompar then it returns true.
    But I dont want it to return true for string 'get data for comparable' with the same regular epression.
    Here, I do not want string comparable and rest all the forms of compar to be selected.

    It's not really clear what you need, perhaps something like this?
    -- data:
    with t as
    select 'get data for comparison' txt from dual union all
    select 'get date for compar xxxxx' txt from dual union all
    select 'compar xx' txt from dual union all
    select 'compare xx' txt from dual union all
    select 'xx compar' txt from dual union all
    select 'xx compare' txt from dual
    -- query:
    select txt from t
    where regexp_like(txt,'(\W|^)compar(\W|$)');
    TXT
    get date for compar xxxxx
    compar xx
    xx compar(\W|^) means word-limit or start of the string
    (\W|$) means word-limit or end of the string
    Edited by: hm on 21.12.2011 05:29

  • Regular Expression / String matching other than equality check with groovy.

    I want to have a string comparison operation using a groovy expression.
    Not an equality check, but something like
    #{variableName like 'IC%'?'true':'false'}
    I saw some operators like
    #{bindings.gradeName.inputValue =~ 'IC'?true:false}
    But it doesnt seem to be working.
    Is it possible with groovy?
    Arun

    Hi
    nything will do.
    And not using bean.
    This expression has to added in an AMX page (ADF Mobile
    It depends on where you want to execute this. Groovy in a validation script would be different to EL in a page as they would be in different stages in the lifecycle.
    Now for ADF MObile this may be different, I dont know.'
    If its to be part of a validation then you can call the source methods in groovy and do the comparison.
    from a validator for instance:
    source.getGradeName() returns the grade name before commiting.
    String enteredgrade = source.getGradeName();
    if (enteredgrade.index(0).equals('I') and enteredgrade(1).equals('C'){
    do what you want here. i.e. return true or false etc.
    el in a page would look entirly different but you can implement this same functionality in a bean, access it via the accessors and then return true or false.
    if you are already using EL and you managed to link your page with JSTL, you will have to define the access variable in the header section inorder to access it and then use "startswith", though I havent tried it this way.

  • Command line arguments to a string

    I run a script on CLI with n number of parameters like this...
    <pre>bash myScript one two three four</pre>
    How can I get within the script a string represented as "onetwo+threefour"

    Wonderful. Thank you.
    I was trying this with quicksilver to use "Google i am feeling lucky".
    Rather than opening a window in firefox and typing in my search terms and clicking the lucky button, with this script I can do something like
    <pre class="jive-pre">Gifl.sh [steer mouse]</pre>
    or any search term and it will take me to steermouse website.
    <pre class="jive-pre">
    #!/usr/bin/env bash
    for arg
    do
    variable="$variable+$arg"
    done
    variable="${variable#+}"
    open "http://www.google.com/search?hl=en&source=hp&q=$variable&btnI=I%27mFeelingLucky&aq=f&oq=&aqi="
    </pre>
    May be there is a quicksilver way of doing this but I cant find it on google.

  • Regular Expressions / String Match

    Hi Everyone,
    thankx for reading this
    I'm programing a oracle form which at one part read's the full path into a file (a text file) and place's it on a VARCHAR2 field. This is the path into the file and not the file data.
    I would like to match this string (the file path) to a another one (in order to know if the file name respect some rules). This is a very easy thing to do under Perl / PHP and other languages. But how can i do this under PL/SQL ?
    I have search but failed to find any clue.
    Any pointers would be great, or a small example
    Thankx Stay Happy
    Miguel Angelo

    Hi,
    you can use INSTR and SUBSTR for String comparison
    INSTR(char1,char2) shows you the first occurence of char2 in char1
    INSTR(char1,char2,n,m)
    shows the m'th occurence of char2 in char1 starting on n
    Frank

  • Regular Expression / String question?

    Ok, So I want to do a String.split and split by a
    (.*)But since parenthese's are regex, how would I search for that without messing up the call?

    CButz wrote:
    so
    \(.*\)should work?Yup.
    But note that if the regex is Java string literal--that is, in your source code in double quotes, as opposed to being read from user input or a config file, you'll need to double the backslash.
    "\\(.*\\)"Also, note that that regex will match (abc)def(ghi) as one group. The abc)def(ghi will match the .*

  • Parsing in Weblogic/jsp doesn't work; application-mode (command-line) works

    Hello-
    Parsing my XML file in Weblogic/jsp doesn't work, whereas it works
    in application-mode... (albeit on two different machines)
    Here are the parameters:
    server1:
    weblogic 6.0
    win2k server
    jre1.3
    my personal machine:
    ***no weblogic***
    win2k server
    jre1.3
    When I run my code as an application (command-line style) on my machine,
    parsing in my xml file works fine, and I can do a root.toString() and it
    dumps out the entire xml file, as desired.
    However, running my code inside weblogic (on server1) in JSP, parsing in
    my file and doing a root.toString() results in the following: [dmui: null]
    (where dmui is my root)
    (even though i'm running it on two different machines, i'm positive its the
    same code (the servers share a mapped drive)...
    So, I think its probably because I'm using a different parser, as
    specified by weblogic? There are no exceptions being thrown. Here's my
    (abbreviated) code, which is called either command line style or in a JSP:
    // Imports
    import org.w3c.dom.*;
    import org.w3c.dom.Document;
    import javax.xml.parsers.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    DocumentBuilderFactory docBuilderFactory =
    DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    mDocument = docBuilder.parse (inFile);
    myRoot.toString()
    -END
    Doing a System.getProperty("javax.xml.parsers.DocumentBuilderFactory")
    results in:
    server1 (weblogic/jsp):
    "weblogic.apache.xerces.jaxp.DocumentBuilderFactoryImpl"
    my machine (application-mode):
    null
    Does anyone have any ideas about how to get this work? Do I try to set it
    up so that they both use the same parser? Do I change the Weblogic parser?
    If so, to what? And how?
    Am I even close?
    Any help would be appreciated..
    Thanks, Clint
    "[email protected]" <[email protected]> wrote in message
    news:[email protected]...
    No problem, glad you got it worked out :)
    ~Ryan U.
    Jennifer wrote in message <[email protected]>...
    I completely missed setting the property(:-o), foolish mistake. That wasit. Thanks.
    "j.upton" <[email protected]> wrote:
    Jennifer,
    Personally I would get rid of import com.sun.xml.parser.* and use xerces
    which comes with WLS 6.0 now, unless like I said earlier you have a need
    to
    use the sun parser :) Try something like this with your code --I've put
    things to watch for as comments in the code.
    import javax.xml.parsers.*;
    import org.xml.sax.SAXException;
    import org.w3c.dom.*;
    import java.io.FileInputStream;
    public class BasicDOM {
    public BasicDOM (String xmlFile) {
    try{
    FileInputStream inStream;
    Document document;
    /*You must specify a parser for jaxp. You can in a simple view
    think
    of this as being analogous to a driver used by JDBC or JNDI. If you are
    using this in the context of a servlet or JSP and have set an XML
    registry
    with the console this happens automatically. You can also invoke it in
    the
    context of an application on the command line using the -D switch. */
    System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
    >>>
    "weblogic.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
    // create a document factory
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    // specify validating or non-validating parser
    dbf.setValidating(true);
    // obtain a factory
    DocumentBuilder db = dbf.newDocumentBuilder();
    // create a document from the factory
    inStream = new FileInputStream(xmlFile);
    document = db.parse(inStream);
    }//try
    catch (Exception e)
    System.out.println("Unexpected exception reading document!"
    +e);
    System.exit (0);
    }//catch
    }//BasicDom
    // Main Method
    public static void main (String[] args) {
    if (args.length < 1)
    System.exit(1); file://or you can be more verbose
    new BasicDOM(args[0]);
    }//class
    =============================================
    That will give you a basic DOM you can manipulate and parse it fromthere.
    BTW this code
    compiled and ran on WLS 6.0 under Windows 2000.
    Let me know if this helped or you still are having trouble.
    ~Ryan U.
    "Jennifer" <[email protected]> wrote in message
    news:[email protected]...
    Actually I included com.sun.xml.parser.* as one last febble attempt toget
    it working.
    And as for source code, I included the code. If I just put that oneline
    of code
    in, including the imports, it fails giving me an error listed above inthe
    subject
    line. Here is the code again:
    package examples.xml.http;
    import javax.xml.parsers.*;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.w3c.dom.*;
    import java.util.*;
    import java.net.*;
    import org.xml.sax.*;
    import java.io.*;
    public class BasicDOM {
    static Document document;
    public BasicDOM (String xmlFile) {
    try {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    } catch (FactoryConfigurationError e){
    System.err.println(e.getException());
    e.printStackTrace();
    // Main Method
    public static void main (String[] args) {
    BasicDOM basicDOM = new BasicDOM (args[0]);

    Hi, Rob
    Does it work in WL9.2?
    It seems I do it exactly as the explained at http://edocs.bea.com/wls/docs81/programming/classloading.html - and it fails :o(.
    I try to run my app.ear with WL9.2 There are 2 components in it: webapp and mdb. The webapp/WEB-INF contains weblogic.xml:
    <weblogic-web-app>
    <container-descriptor>     
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>
    </weblogic-web-app>
    Mdb is expected to run in the same mode, i.e. to prefer the webapp/WEB-INF/*.jar over the parent Weblogic classloader. To do so I add the weblogic-application.xml to the app.ear!/META-INF:
    <weblogic-application>
    <classloader-structure>
    <module-ref>
    <!-- reminder: this webapp contains
    prefer-web-inf-classes -->
    <module-uri>webapp</module-uri>
    </module-ref>
    <classloader-structure>
    <module-ref>
    <module-uri>mdb.jar</module-uri>
    </module-ref>
    </classloader-structure>
    </classloader-structure>
    </weblogic-application>
    Now, when classloader-structure specified, both webabb and mdb prefer the weblogic root loader as if prefer-web-inf-classes not defined at all.

  • Regular Expression to capture user's input string

    I am writing a helper class to split user input string into String array according to the following pattern:
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class TestDelimiter {
    static Pattern p = Pattern.compile("(.*?)[,;]{1}");
    static Matcher m;
        public static void main(String[] args) {
            String input = "AAA111111,BBB222222;CCC333333";
            m = p.matcher(input);
            while(m.find()){
                String output = m.group(1);
                System.out.println(output);
    }Output:
    AAA111111
    BBB222222My question is, how can I modify the regular expression string so that the CCC333333 (last element) can also be included?

    roamer wrote:
    Ok, let's don't argue on this point.Who's arguing?
    I think I got the answer. For simplicity, I can just manually add a ";" or "," string after each user input. Just like:You never said anything about that before. You asked how to split "AAA111,BBB222;CCC333" into its components and you were given a correct answer.
    Maybe you should rephrase your question including this added requirement. Do you need to have the separator included in the final outputs or why do you want to suddenly add things to user input?

  • Regular expression for 2nd occurance of a substring in a string

    Hi,
    1)
    i want to find the second occurrence of a substring in a string with regular expression so that i can modify that only.
    Ex: i have a string like ---> axe,afn,sdk,jdi,afn,mki,mki
    in this i want the second occurance of afn and change that one only...
    which regular expression i have to use...
    Note that ...i have to use regular expression only....no string manipulation methods...(strictly)
    2)
    How can i apply the multiple regular expressions multiple times on a single string ..i.e in the above instance i have to apply the same 2nd occurrence logic for
    substring mki also. for this i have to use a single regular expression string that contains validations for both the sub strings mki and afn.
    Thanks in advance,
    Venkat

    javafreak666 wrote:
    Hi,
    1)
    i want to find the second occurrence of a substring in a string with regular expression so that i can modify that only.
    Ex: i have a string like ---> axe,afn,sdk,jdi,afn,mki,mki
    in this i want the second occurance of afn and change that one only...
    which regular expression i have to use...
    Note that ...i have to use regular expression only....no string manipulation methods...(strictly)
    2)
    How can i apply the multiple regular expressions multiple times on a single string ..i.e in the above instance i have to apply the same 2nd occurrence logic for
    substring mki also. for this i have to use a single regular expression string that contains validations for both the sub strings mki and afn.
    Thanks in advance,
    VenkatWhat do you mean by using a regex to get the index of a second substring? There is not method in Java which uses regex to et the index of a substring.
    There are various indexOf(...) methods for this:
    String text = "axe,afn,sdk,jdi,afn,mki,mki";
    String target = "afn";
    int second = text.indexOf(target, text.indexOf(target)+1);
    System.out.println("second="+second);Of course you can find the index of a group like this:
    Matcher m = Pattern.compile(target+".*?("+target+")").matcher(text);
    System.out.println(m.find() ? "index="+m.start(1) : "nothing found");but there is not single method that handles this: you'll have to call the find() and then the start(...) method on the Matcher instance, so the indexOf(...) approach is the favourable one, IMO.

  • Regular Expressions and Double Byte Characters ?

    Is it possible to use Java Regular Expressions to parse
    a file that will contain double byte characters ?
    For example, I want a regular expression to match the following line
    tag="double byte stuff" id="double byte stuff"

    The comments on the bytes/strings were helpful. Thanks.
    But I'm still confused as to what matching pattern could be used.
    For example a pattern like:
    [A-Za-z]
    I assume would not match any double byte characters.
    I also assume the following won't work either:
    [\\p{Alpah}]
    because it is posix - US-ASCII only.
    So how do you say "match the tag, then take any characters,
    double byte, ascii, whatever, then match the text tag - per the
    original example ?

Maybe you are looking for