Results 1 to 19 of 19

Thread: Greedy,Reluctant,Possessive Quantifers?

Threaded View

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Resolved Greedy,Reluctant,Possessive Quantifers?

    Anyone know what the similarities or differences are between these quantifers? Under the docs the descriptions are all the same.

    Greedy quantifiers
    X? X, once or not at all
    X* X, zero or more times
    X+ X, one or more times
    X{n} X, exactly n times
    X{n,} X, at least n times
    X{n,m} X, at least n but not more than m times

    Reluctant quantifiers
    X?? X, once or not at all
    X*? X, zero or more times
    X+? X, one or more times
    X{n}? X, exactly n times
    X{n,}? X, at least n times
    X{n,m}? X, at least n but not more than m times

    Possessive quantifiers
    X?+ X, once or not at all
    X*+ X, zero or more times
    X++ X, one or more times
    X{n}+ X, exactly n times
    X{n,}+ X, at least n times
    X{n,m}+ X, at least n but not more than m times

    Also how are these quantifers used? I made a simple test program using the greedy,reluctant,possessive quantifiers(X, once or not at all) quantifers
    but i don't understand the output.
    Code:
     import java.util.*;
     
     public class X{
      public static void main(String[] args){
     
       String data = new String("mxpxr");
       Scanner s = new Scanner(data);
      // s.useDelimiter("x"); //  returns mpr
      // s.useDelimiter("x?"); // returns mpr{greedy quantifer}
      // s.useDelimiter("x??");  // returns mxpxr{reluctant quantifer}
      // s.useDelimiter("x?+"); // returns mpr{possessive quantifer}
       while(s.hasNext()){
         System.out.println(s.next()); 
       }
      }
     }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width