Results 1 to 6 of 6

Thread: Regex retrieve the value that matches

  1. #1
    Join Date
    Dec 2009
    Posts
    263

    Regex retrieve the value that matches

    Hello,
    I tested this snippet works:
    Code:
    String reg = "[0-9]*";
    String in = "test0123test";
    Boolean ismat = Pattern.games(reg, in);
    but I try to retrieve the string "0123" a match that my expression "[0-9] *"
    How? With this Regex how can I retrieve the value that matches. Thank you in advance

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Regex retrieve the value that matches

    Hello,
    It would be preferable to use the expression "[0-9]+"If you have lots of empty string in result
    Code:
    	Matcher mth = Pattern.compiles(regex).mth(input);
    	while (mth.find()) {
    		System.out.System.out.println(mth.group());
    	}
    Hope this will help you. If more problem then do post back.

  3. #3
    Join Date
    Dec 2009
    Posts
    263

    Re: Regex retrieve the value that matches

    Hello,
    Thanks for your reply . I take this opportunity to ask you if you know a site where I can find regular expressions representing the dates like:
    08/11/2009
    Wed, Jul 5, 02
    02002.July.04 AD 12:08 PM
    etc...
    like what the class SimpleDateFormat, but unlike (of String to Date). The goal is to make a class that parses a text and return the Date. should I write the words one by one? Thank you

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    Re: Regex retrieve the value that matches

    Hello,
    But SimpleDateFormat can also return dates from String. Interested now in its parse method.
    Code:
    SimpleDateDormat sdf = new SimpleDateFormat("dd / MM / yyyy");
    Date date = sdf.parse("20/04/1990");
    Just try this, it is very easy with this way.

  5. #5
    Join Date
    Dec 2009
    Posts
    263

    Re: Regex retrieve the value that matches

    Hello,
    I know this function but the problem with is that one must know the date format to be able to parse one! Now I want to parse a text (that of an email for example) and retrieve all appointments.
    eg I'll see you Friday, January 23, 2009.
    I want the function to parse my post and finds it a date. I think this is bit semantic. Should I enter all the possible combination's? Any help on this is appreciated.

  6. #6
    Join Date
    Nov 2009
    Posts
    330

    Re: Regex retrieve the value that matches

    Hello,
    Just have a look at the following example, this is the basic thing to do in your case
    Code:
    public class SampleRegex
    {
       public static void main(String[] params)
       {
          Pattern pat = Pattern.compile("(.*):(.*)");
          Matcher mat = pat.mat(params[0]);
          if(mat.matches())
          {
             System.out.print("Key:");
             System.out.println(mat.group(1));
             System.out.print("Value:");
             System.out.println(mat.group(2));
          }
          else
             System.out.print("No match");
       }
    }

Similar Threads

  1. Sum up a number of matches in Vlookup in Excel
    By Abélard in forum MS Office Support
    Replies: 2
    Last Post: 24-02-2012, 06:58 PM
  2. Conventional MP matches in FEAR 3
    By rUChIRr in forum Video Games
    Replies: 5
    Last Post: 02-06-2011, 10:09 PM
  3. Multiple Matches Return To VLOOKUP
    By Brunon in forum Windows Software
    Replies: 5
    Last Post: 26-11-2010, 11:32 PM
  4. Matches in WWE SmackDown
    By Romany in forum Video Games
    Replies: 5
    Last Post: 29-03-2010, 10:28 AM
  5. Regex matches last index
    By Mindstorm in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 06:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,414,120.22296 seconds with 16 queries