Results 1 to 4 of 4

Thread: Change pattern of an existing pattern object?

Threaded View

  1. #1

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

    Change pattern of an existing pattern object?

    Is there anyway that i could reuse an existing pattern object and just change the pattern without having to create a whole new pattern object by compiling it? Plus i am getting an error variable p might not have been initialized
    Code:
     import java.util.*;
     import java.util.regex.Pattern;
     import java.util.regex.Matcher;  
    
     public class X{
      public static void main(String[] args){
     
       String flavors = new String("marshmellowipeanutbutter   i   rockyroad");
       Pattern p = p.compile("\\s*i\\s*");
       // want to keep the same pattern object just change the pattern 
       Scanner s = new Scanner(flavors); //.useDelimiter("\\s*i\\s*"); 
       Matcher m = p.matcher(flavors);
       if(m.matches()){ 
        while(s.hasNext(p)){
         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