This discussion is archived
1 Reply Latest reply: Nov 27, 2012 4:44 AM by rukbat RSS

Regex clarification

818747 Newbie
Currently Being Moderated
Hi ,

How can i write a regex that matches the word Time/Mandatory/Request in same order.Is the below approach correct.
public class Test {
     public static void main(String[] args) {
     String text ="1A Type: Air code H&C Text: [Time Mandatory If Time Window Requested]";
     //Trying to match tha pattern for the text in the same order.
     //String pattern1="[Time]|[Mandatory]|[Requested] ";
//     String pattern1="^.*Time.*$";//(?=.*?\bMandatory\b)(?=.*?\bRequested\b).*$";
     String pattern1="^(?=.*?\bTime\b).*$" ;
     Pattern p = Pattern.compile(pattern1);
     Matcher m = p.matcher(text);
     while (m.find()) {
          System.out.print("matched");
     }
     }     
}{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  • 1. Re: Regex clarification
    rukbat Guru Moderator
    Currently Being Moderated
    You already have an inquiry on this topic from a few short weeks ago:
    Regex

    You seem to have abandoned that forum thread. You need to return to it and continue your discussion there. That will keep all your information in the same thread.

    This post is now locked.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points