Regex & java.util.Scanner

I am trying to make a simple txt parser using regular expressions but the problem has
appeared.
The program's code is too long so I have stated only the part of the code implementing
the method data_types() which doesn't work properly, it reads only two types (String) and (Boolean). If someone could help me I would be very gratefull.Why method doesn't read the rest of data types in my data_xml.xml file?
here is the code >
class SimpleScann{
       enum PARSE{
          TABLE_NAME("(\\w*)"),COLUMN_NAME("(\\w*\\Q(\\E)"),DATA_TYPE("(\\Q(\\E\\w*\\Q)\\E)");
          private String $pattern;
          PARSE(String pattern){
               $pattern=pattern;
          public String PATTERN(){
               return $pattern;
     static void data_types() throws Exception{     
          File parse_file= new File("data_type.txt");
          Scanner     scann_input = new Scanner(parse_file);     
          int flag= Pattern.CASE_INSENSITIVE;
          Pattern pattern=Pattern.compile(PARSE.DATA_TYPE.PATTERN(),flag);
          Matcher matcher=null;
          while(scann_input.hasNextLine()){
               matcher=pattern.matcher(scann_input.nextLine());
               if(matcher.find()){
                    System.out.printf("%s\n",matcher.group());
     public static void main(String args[])
          try{
               data_types();
          }catch(Exception e){
               e.printStackTrace();
and here is the data_type.txt<table          > Table radi
ako su zatvoreni tagovi     <>
<column>
     Ime(String), Prezime(String), JMBG(Integer) ,
     Enabled(Boolean)
<\column>
best regards,
Nikola

The reason you're only matching two items is because you're reading the file one line at a time and applying the regex once per line. As Tim said, you can fix that by using while instead of if, but the real problem is much deeper: you're trying to write a scanner in the sense of a lexical analyzer, and that isn't what java.util.Scanner is for. I strongly recommend you start over, this time using Pattern and Matcher directly, not Scanner. If you happen to have a copy of MRE 3ed, there's an example of what you're trying to do on page 400. (Unfortunately, Friedl has just moved back to Japan, and hasn't had time to update the book's web site, or I could point you to the code online.) I don't have time to go into this right now, but you should pay particular attention to the find(int) method and the \G anchor.

Similar Messages

  • The import "java.util.scanner" is not vaild

    I am experiment with the java.util.scanner API after compiling the code below I received the following error:
    The import "java.util.Scanner" is not valid, since it does not name a type in a package.
    I declared a string variable should that suffice?
    import java.util.Scanner;
    public class Echo {
    public static void main (String[] args)
    String message;
    Scanner scan = new Scanner (System.in);
    System.out.println ("enter something:");
    message = scan.nextLine();
    System.out.println ("hey you entered: \"" + message + "\"");
    }

    Most IDEs let you select and installed JDK for them to use. Check out that IDE's preferences.
    Otherwise, start here and learn to do it with a simple text editor or programmer's editor, and the command line.
    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/

  • Error when importing java.util.Scanner

    Agh! I'm in an introduction to computer science course, and I am writing a program as an assignment that's due tomorrow.
    I have imported java.util.Scanner before, but I've only run it on the Windows PCs in the lab, whereas I am currently on a Mac. I've updated to the latest version of Java (through the software update), and I'm running Tiger (also fully updated).
    I'm using Dr. Java to write the programs, but I tried using the very same thing in Eclipse and it didn't work. Here's my program:
    import java.util.Random;
    import java.util.Scanner;
    public class Password {
    public static void main(String[] args) {
    //create a Scanner object to read from the keyboard:
    String password;
    Scanner scanner = new Scanner(System.in);
    Random randomizer = new Random();
    System.out.println("Please enter a string containing candidate characters.");
    String input = scanner.next();
    int charLength = length(input);
    System.out.print("Random password: ");
    System.out.print(input.substring(randomizer.nextInt(charLength)));
    System.out.print(input.substring(randomizer.nextInt(charLength)));
    System.out.print(input.substring(randomizer.nextInt(charLength)));
    System.out.println(input.substring(randomizer.nextInt(charLength)));
    And, here's my errors:
    4 errors found:
    File: /Users/brianmoore/Desktop/Password.java [line: 11]
    Error: cannot resolve symbol
    symbol : class Scanner
    location: package util
    File: /Users/brianmoore/Desktop/Password.java [line: 18]
    Error: cannot resolve symbol
    symbol : class Scanner
    location: class Password
    File: /Users/brianmoore/Desktop/Password.java [line: 18]
    Error: cannot resolve symbol
    symbol : class Scanner
    location: class Password
    File: /Users/brianmoore/Desktop/Password.java [line: 22]
    Error: cannot resolve symbol
    symbol : method length (java.lang.String)
    location: class Password
    Any ideas?

    Ok. I figured it out. On the Dr. Java page, this is what helped me:
    Please verify the following:
    - Open "/Applications/Utilities/Java/J2SE 5.0/Java
    Preferences";
    make sure "J2SE 5.0" is at the top of the list under
    "Java
    Application Runtime"
    - Open DrJava; go to Edit->Preferences; make sure
    "Tools.jar
    Location", "JSR-14 Location", and "JSR-14
    Collections Path"
    are all blank
    - Open the Help->About dialog box; make sure the "DrJava
    Version" listed is 20050601-0007 or later (that is, later
    than
    June 1, 2005)
    - Go to the "System Properties" tab in the
    "About" box; make
    sure "java.version" is 1.4.2.
    Let us know what you find out if you're still having
    trouble.
    Thanks for your help!

  • What the HELL with java.util.Scanner

    Hello people...
    Somebody have a pointer that teaches how to work with Scanner, or everybody fells like me, as this API just don't work well!!!?
    At this right moment I have the same JAR file, run something at linux and work well, but when at windows got an exception...

    http://java.sun.com/developer/JDCTechTips/2004/tt1201.html
    http://java.sun.com/docs/books/tutorial/essential/io/scanning.html
    ~Tim

  • How To Color a Text string using Regex (java.util.regex)

    Hello,
    How can I color a text string using regex class in 1.4?

    Yes, did you notice it said something about incredibly vague functionality?
    Let me break it down for you
    > How can I color a text string
    Strings do not have color... You can color a component (a label, a button), but you can't color a string
    > using regex class in 1.4?
    Using a regular expression? How would a regular exression color anything? Do you have embedded color codes? Are you searhing a string for some secret word?
    What are you talking about?

  • Input via java.util.Scanner

    I know it's possible for JDeveoper 10G to take input via BufferedReader, is the same possible using the scanner class as in:
    Scanner input = new Scanner(System.in);
    System.out.println("Enter your age");
    int age = input.nextInt();
    System.out.println("You are " + age);
    JDeveloper can't seem to take imput from the scanner class. Is there a way arround this?
    Andrew.

    I am aware of that Shay, but it does not work for the Scanner Class, at least for me anyway.
    Try the following example code in JDeveloper 10.1.3 I constructed this to put the Scanner though its paces for the Job I need.
    It works very well when used from the command line, but cannot be read with JDeveloper even with those settings you describe turned on.
    Scanner input = new Scanner(System.in);
    System.out.println("Enter your age");
    int age = input.nextInt();
    System.out.println("You are " + age);
    System.out.println("what is your name?");
    String name = input.next();
    System.out.println("Yout name is " + name);
    System.out.println("Please enter your height");
    double height = input.nextDouble();
    System.out.println("So you are " + height + " tall.");
    System.out.println("What sex are you M/F?");
    char sex = input.next().charAt(0);
    if (sex == 'm' || sex == 'M')
    System.out.println("Ahh so your a male");
    else if (sex == 'f' || sex == 'F')
    System.out.println("Ah you your a femaile.");
    System.out.println("You are English right? (True/alse)?");
    boolean eng = input.nextBoolean();
    System.out.println("Right so it's " + eng + " that your English. You are " + age + " years of age, and your name is " + name + ", your sex is " + sex + " and you are " + height + " tall.");
    Message was edited by:
    Scottie_UK

  • Unexpected java.util.Scanner behaviour

    Is it just me or do others find the following behaviour strange? It seems that in order to break out of the loop in the following, it's necessary to enter some character(s) unparseable as a double. Hitting return won't cause it to break:
         public static void scanInts(String[] args) {
              Scanner scanner = null;
              List<Double> coefficients = new ArrayList<Double>();
              double x = Double.NaN;
              try {
                   scanner = new Scanner(System.in);
                   while(scanner.hasNextDouble()) {
                        double d = scanner.nextDouble();
                        System.out.println("double=" + d);
                        coefficients.add(d);
                   System.out.println("Now out of loop");
              finally {
                   System.out.println(coefficients);
                   scanner.close();
         }

    I don't think it's strange; Scanner is supposed to ignore extra whitespace and line breaks are whitespace. You can change this behaviour by setting the delimiter to something else, like:scanner.useDelimiter("[ ]*");

  • Exception: Scanner - java.util.NoSuchElementException: No line found ???

    Hi there,
    I have the following code:
    import java.util.InputMismatchException;
    import java.util.Scanner;
    public class Input {
         public static String readString() {
              return _readString(null, null);
         public static String readString(String title) {
              return _readString(title, null);
         public static String readString(String title, String error) {
              return _readString(title, error);
         private static String _readString(String title, String error) {
              Scanner input = new Scanner(System.in);
              boolean loop = true;
              String str = null;
              while(loop) {
                   try {
                        if(title != null) {
                             System.out.print(title);
                        str = input.nextLine();
                        loop = false;
                   } catch(InputMismatchException e) {
                        if(error != null) {
                             System.out.println(error);
              input.close();
              return str;
    public class Program {
         public static void main(String[] args) {
              String a;
              a = Input.readString("VALUE: ");
              System.out.println(a);
              a = Input.readString("\nVALUE: ");
              System.out.println(a);
    }And the following output:
    VALOR: Hello World!
    Hello World!
    VALUE: Exception in thread "main" java.util.NoSuchElementException: No line found
         at java.util.Scanner.nextLine(Scanner.java:1516)
         at Input._readString(Input.java:29)
         at Input.readString(Input.java:11)
         at Program.main(Program.java:21)The first value is read without any problems but the second throws that exception. Why is this happening? I "fixed" it by removing the input.close(); line but this makes no sense to me. First because I think that I should close the Scanner after using it and second because every time I call the _readString() method, a new Scanner instance will be created, so it doesn't make sense... At least for me, but that's why I'm posting on this forum section, cause I'm new to Java.
    Can someone explain me why exactly does this happen and if possible, a better solution then to remove the input.close()? It just doesn't make any sense to me create a new Scanner instance every time I call the _readString() method and leave it there without closing it...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    First because I think that I should close the Scanner after using it and
    second because every time I call the _readString() method, a new Scanner instance will be createdUmm, NO.
    Let me see if I understand things in the Static world correctly.
    Notice that you have everything declared as "Static" in your Class. A static is only initialized at programs start and everything in your JVM can then us it (well that stuff that has a reference to it). Since it's static, when you close the Scanner, you are closing the only instance that will ever exist in your object.
    For things to work how you think they should, get rid of the Static declarations (excpet in main, where you have to keep them).

  • Static class containing scanner throws java.util.NoSuchElementException

    I use the scanner class pretty often in my coding and recently i have been trying to create a static method i can put in an external class to do the scanning for me and trap any errors.
    I seem to be able to create the class successfully but i have a slight problem in that i cannot use the method twice in the same program without having it throw a java.util.NoSuchElementException
    If anyone could figure out what error i have made and suggest a way to fix it i would be very grateful
    code is as follows:
    Scan.java:
    // name information removed for privacy
      // class info removed for privacy
      Assignment: 4.3,
      File Name: /ASSIGNMENTS/ASSIGNMENT_4/Part3/Scan.java
    import java.util.Scanner;
    public class Scan
      public static double nextDouble (String prompt)
        // variable to hold the result
        double result = 0.0;
        // variable to determine if input was ok
        Boolean inputOK = false;
        // do-while loop to get some input
        do
          // print the prompt. what do you want to ask for?
          System.out.print ( prompt );
          // Try to scan and capture the input and catch the exception
          try
            // create the scanner object
            Scanner scan = new Scanner (System.in);
            // parse the input`
            result = scan.nextDouble();
            // if we reach this step then good. we got good input let's exit the loop
            inputOK = true;
            // close the scanner
            scan.close();
          // oops we got an error!
          catch (java.util.InputMismatchException e)
            // inform the user of the error
            System.out.println ("That is not a number! Try again. \n");
            // input was not ok so we can't exit the loop yet
            inputOK = false;
        // keep looping as long as inputOK is false
        } while (!inputOK);
        // return out result
        return result;
    }Mathematics.java:
    // name information removed for privacy
    // class information removed for privacy
    * Assignment: 4.3
    * File Name: ASSIGNMENTS/ASSIGNMENT_4/Part3/Mathematics.java
    // Import Scanner class
    import java.util.Scanner;
    //Class Body
    public class Mathematics{
    // Main method. AUTO EXECUTE
      public static void main(String[] args)
    // additional variable declarations removed for brevity
        // Create double precision floating point variables
          double  coeff4 = 0.0, coeff3 = 0.0, coeff2 = 0.0, coeff1 = 0.0, cons = 0.0;
        coeff4 = Scan.nextDouble("Enter the coefficient of x^4 (0.0 if none): ");
        coeff3 = Scan.nextDouble("Enter the coefficient of x^3 (0.0 if none): ");
        coeff2 = Scan.nextDouble("Enter the coefficient of x^2 (0.0 if none): ");
        coeff1 = Scan.nextDouble("Enter the coefficient of x (0.0 if none): ");
        cons = Scan.nextDouble("Enter the constant (0.0 if none): ");
    // do fun things with input (code removed for brevity)
    }output looks like this
    dragonfly@Home:~/ASSIGNMENTS/ASSIGNMENT_4/Part3$ java Mathematics
    Enter the coefficient of x^4 (0.0 if none): hello boys!
    That is not a number! Try again.
    Enter the coefficient of x^4 (0.0 if none): 1.2.
    That is not a number! Try again.
    Enter the coefficient of x^4 (0.0 if none): d
    That is not a number! Try again.
    Enter the coefficient of x^4 (0.0 if none): 1
    Enter the coefficient of x^3 (0.0 if none): Exception in thread "main" java.util.NoSuchElementException
            at java.util.Scanner.throwFor(Scanner.java:817)
            at java.util.Scanner.next(Scanner.java:1431)
            at java.util.Scanner.nextDouble(Scanner.java:2335)
            at Scan.nextDouble(Scan.java:23)
            at Mathematics.main(Mathematics.java:34)
    dragonfly@Home:~/ASSIGNMENTS/ASSIGNMENT_4/Part3$

    Through trial and error i seem to have hit upon a solution to my problem. i am stress testing it now but i think it will hold up admirably
    import java.util.Scanner;
    public class Scan
    // scan in a double without a prompt. catch and handle any exceptions
    public static double nextDouble ()
        return nextDouble("");
    // give the user a prompt and then scan in a double. catch and handle any exceptions
    public static double nextDouble (String prompt)
        // variable to hold the result
        double result = 0.0;
        // variable to determine if input was ok
        boolean inputOK = false;
        // do-while loop to get some input
        do
          // print the prompt. what do you want to ask for?
          System.out.print ( prompt );
          // Try to scan and capture the input and catch the exception
          try
          // Call private method to do the actual scanning
            result = scanDouble();
            // if we reach this step then good. we got good input let's exit the loop
            inputOK = true;
          // oops we got an error!
          catch (java.util.InputMismatchException e)
            // inform the user of the error
            System.out.println ("That is not a number! Try again. \n");
            // input was not ok so we can't exit the loop yet
            inputOK = false;
        // keep looping as long as inputOK is false
        } while (!inputOK);
        // return out result
        return result;
    // Helper method to nextDouble
      private static double scanDouble()
      // hold the result
        double result=0.0;
      // create the scanner object
        Scanner scan = new Scanner (System.in);
      // parse the input
          // If input was not of proper type this call will fail with :
          // java.util.InputMismatchException
          // and return control to calling method
        result = scan.nextDouble();
      // Return our findings
        return result  ;
    }

  • Errormessage: "java.util.NoSuchElementException"

    Why can't I compile the following code?
    Im using MAC OSX 10.4.10 with the latest J2SE 5.0 Preferences
    import java.util.Scanner;
         class gumballs {
              public static void main(String args[]) {
                   Scanner myScanner = new Scanner(System.in);
                   int gumballs;
                   int kids;
                   int gumballsPerKid;
                   System.out.print("How many gumballs? How many kids? ");
                   gumballs = myScanner.nextInt();     
                   kids = myScanner.nextInt();
                   gumballsPerKid = gumballs / kids;
                   System.out.print("Each kid gets ");
                   System.out.print(gumballsPerKid);
                   System.out.println(" gumballs.");
    } I get the following error when I try to compile the code
    Exception in thread "main" java.util.NoSuchElementException
         at java.util.Scanner.throwFor(Scanner.java:817)
         at java.util.Scanner.next(Scanner.java:1431)
         at java.util.Scanner.nextInt(Scanner.java:2040)
         at java.util.Scanner.nextInt(Scanner.java:2000)
         at gumballs.main(gumballs.java:14)
    How many gumballs? How many kids?
    Program exited with status 1.Please help me! im just a newbie trying to learn java..
    Thanks

    Im on XP and getting the same error message :(
    It compiles fine but when I run it and I am done inputing it gives me that same error message.
    And yes I am running the latest version of JDK
    Also I am having a strange probleming trying to run my files in the command prompt. I can get it to compile fine javac helloworldapp.java and it creates the class. I know my Universal variables are set correctly but when I try java helloworldapp after I have compiled I get a similar error message. I dont know if this is at all related I just started using Java last night so I am a total newb. I would appreciate if one of you pro's could help me out.
    thank you

  • Please help - Java.util Error! Have no clue! - Please Help

    Hey guys,
    Im very new to java,
    With my code here :
    import.java.util.Scanner;
       public class delta{
       public static void main(String args[]){
            Scanner done = new Scanner(System.in.());
            System.out.println(done.nextLine);
    }I am unable to compile due to a Java.utill error!, can someone please tell me where i am going wrong? or provide me with a guide on how to setup netbeans because i think that is where i am going wrong !
    -thanks!

    815788 wrote:
    its
    package <error>.java.util does not exist.it also doesn't let me compile because of this.And, to fill in the information you didn't yet post, this referred to your "import" line, right? Please don't hoard information. Tell us what the problem is.
    As to the fix, look at your "import" statement and compare it to "import" statements in your textbook or tutorial or notes or whatever you're learning from.

  • Java.util.inputmismatchException

    Exception in thread "main" java.util.InputMismatchException
    at java.util.Scanner.throwFor(Scanner.java:840)
    at java.util.Scanner.next(Scanner.java:1461)
    at java.util.Scanner.nextInt(Scanner.java:2091)
    at java.util.Scanner.nextInt(Scanner.java:2050)
    at Trials.GradeBook.inputGrades(GradeBook.java:48)
    at Trials.GradeBookTest.main(GradeBookTest.java:18)
    could you plz xplain y i get this error message during building process

    import java.util.Scanner;
    public class GradeBook {
        private String courseName;
        private int total;
        private int gradeCounter;
        private int aGrade;
        private int bGrade;
        private int cGrade;
        private int dGrade;
        private int fGrade;
        // constructor of the class GradeBook
        public GradeBook(String name1) {
            courseName=name1;
        // initialize the value of the field courseName
        public void setCourseName(String name){
            courseName=name;
        // get the value of the field and return it to method caller
        public String getCourseName(){
            return courseName;
        // input the grades from user useing sentinel control loop
        public void inputGrades(){
            int grade;
            Scanner input = new Scanner(System.in);
            System.out.printf("%s\n%s\n%s\n",
                    "Enter the integer grades between 0-100:",
                    "Type end-of-file key to terminate the input",
                    "(i.e <Ctrl>z then press Enter on Windows)");
            while(input.hasNext()){
                grade = input.nextInt();
                total += grade;
                ++gradeCounter;
                // call a method to increment appropriate grade counter
                incrementGradeCounter(grade);
        // mehtod incrementGradeCoutner counts using switch-case loop
        public void incrementGradeCounter(int grade){
            switch(grade/10){
                case 10:
                case 9:
                    ++aGrade;
                    break;
                case 8:
                    ++bGrade;
                    break;
                case 7:
                    ++cGrade;
                    break;
                case 6:
                    ++dGrade;
                    break;
                default:
                    ++fGrade;
                    break;
        // create a method that displays welcome message to grade book user
        public void displayMessage(){
            System.out.printf("\nWelcome to the Grade Book for %s\n",
                    getCourseName());
        public void displayReport(){
            if ( gradeCounter != 0 ){
                System.out.printf("The total of %d grade entered is %d\n",
                        gradeCounter,total);
                System.out.printf("The class average is %.2f",
                        (double)total/gradeCounter);
                System.out.printf("%s\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n",
                        "Number of students who recieved each grade",
                        "A: ",aGrade,
                        "B: ",bGrade,
                        "C: ",cGrade,
                        "D: ",dGrade,
                        "F: ",fGrade);
            else
                System.out.println("Sorry! no grade was entered\n" +
                        "THANK YOU FOR USING THE GRADE BOOK");
    public static void main(String args[]) {
            // create an object of Class GradeBook with its own contructor
            GradeBook myGradeBook = new GradeBook("CS101 Java Programming");
            myGradeBook.displayMessage();
            myGradeBook.inputGrades();
            myGradeBook.displayReport();
        }}

  • Java.util.regex error

    Hello,
    I checked JavaDoc multiple times but do not see what is wrong with
    myString.replaceAll("D:\\web\\mars","")which results in
    java.util.regex.PatternSyntaxException: Illegal/unsupported escape squence near index 7
    D:\web\mars
           ^
         at java.util.regex.Pattern.error(Unknown Source)
         at java.util.regex.Pattern.escape(Unknown Source)
         at java.util.regex.Pattern.atom(Unknown Source)
         at java.util.regex.Pattern.sequence(Unknown Source)
         at java.util.regex.Pattern.expr(Unknown Source)
         at java.util.regex.Pattern.compile(Unknown Source)
         at java.util.regex.Pattern.<init>(Unknown Source)
         at java.util.regex.Pattern.compile(Unknown Source)
         at java.lang.String.replaceAll(Unknown Source)
         at ArticleImageImportProcessor.main(ArticleImageImportProcessor.java:40)
    Exception in thread "main" please, every suggestion/hint is most appeciated

    You have to "encode" backslash twice, first for String purpose and second time because of special meaning of '\' in regular expressions.
    It should looks like
    myString.replaceAll("D:\\\\web\\\\mars","")

  • Who use sql-mapping with java.util.regex?

    Hi everyone:
    I use the IBatis SQL-Mapping and I think it is very good.Now I want to add the search function to my BBS forum.I also want to display the content high light like jive.I mean that if I want to find the string "ibatis",then the search result "ibatis" will be high light displayed.
    So I must use the java.util.regex in jsdk1.4.But the problem is that what I get is a List if I use sql-mapping.For example:
              String resource="conf/XML/sql/lyo-sql-map.xml";
              Reader reader=Resources.getResourceAsReader(resource);
              sqlmap=XmlSqlMapBuilder.buildSqlMap(reader);
              List articlelist=sqlmap.executeQueryForList("selectSiteArticle","%"+icontent+"%");
    The result I get is a List and I have no time to use regex.
    I don't know whether I could do this:
    Iterate the List,use the regex and later place all the object back to the List.
    It's right?
    How to use regex with sql-mapping?Thks

    Any idea? :(

  • Parsing xhtml using java.util.regex

    I am parsing an XHTML file using the java.util.regex package and I am perplexed at why the following doesn�t work.
    The lines I wish to match are either like this:
    <span class="someclass"><b>Some String.</b></span></td>
    or
    Some String.</td>
    The code I use to try to achieve this is:
    Pattern somePattern = Pattern.compile(".*(<span class=\"someclass\"><b>)?(.*)[.](</b></span>)?</td>.*");
    String s = null;
    while((s = br.readLine()) != null) {
    if(somePattern.matcher(s).matches()) {
    System.out.println("0:" + eventMatcher.group(0));
    System.out.println("1:" + eventMatcher.group(1));
    System.out.println("2:" + eventMatcher.group(2));
    System.out.println("3:" + eventMatcher.group(3));
    I expect to get as output
    0:<span class="someclass"><b>Some String.</b></span></td> 1:<span class="someclass"><b>
    2:Some String
    3:</b></span>
    or
    0:Some String.</td>
    1:null
    2:Some String
    3:null
    depending on which lines provide the match as mentioned above. Instead I get:
    0:<span class="someclass"><b>Some String.</b></span></td>
    1:null
    2:(empty string)
    3:</b></span>
    or
    0:Some String.</td>
    1:null
    2:(empty string)
    3:null
    Any ideas? Thanks in advance.

    Consider the terms of ".*(<span class=\"someclass\"><b>)?(.*)[.](</b></span>)?</td>.*"
    .* - greedily collect characters
    (<span class=\"someclass\"><b>)? - optionallly collect information taht will always be matched by the previous .* pattern so will be empty.
    (.*) - greedily collect characters that will also have been swallowed by the first .* so will be empty
    [.] - a single .
    (</b></span>)? - optionally collection
    </td> - must be there
    .* - collect the rest of the charcters in the line.
    Therefore in general groups 1 and 2 will be empty because the first .* will have collected the information you wanted to capture!
    You could just make the first .* non-greedy by using .*? but this may fail for other reasons.
    So, in general terms, what are you trying to extract?

Maybe you are looking for

  • How do I restore just Apple Mail (and all its folders & settings) with TM?

    Hi folks, I was trying to set up an e-mail client on a PC, clicked and unclicked my gmail pop & imap on and off, and when I got home to my Apple MacBook, I had inadvertently reloaded (twice!) every e-mail that I've ever gotten in g-mail to Apple Mail

  • Bapi for release purchase order

    Hi Experts       Is there any BAPI available to release the Purchae Order.      Pls advise me to do the same. regards rajaram

  • Apple TV & mirroring MBP

    Is there a possibility to run the presentation / do mirroring using the Apple TV 2 and iPhone 4/iPad 1/MBP?

  • BI publisher  Linux 64 bit?

    Hi , our server is a linux 64 bit server is BI publisher available in a 64 bit version? I would assume it has to exist thanks

  • Windows OS for iPod Touch

    Is the iPod Touch user manual completely accurate? It says "To use iPod touch, you need: ... Windows Vista Home Premium, Business, Enterprise, or Ultimate edition". But my computer only has Windows Vista Home Basic installed. PS. Why can't I find an