CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 1 of 1
  1. #1
    Join Date
    Jul 2013

    A simple hand with Java Pattern Matching?

    I have had a good go at using Java OpenJDK, necessarily a very early version of the OpenJDK, in order to try and match expressions like the following, which are going to be certain kinds of doubles in exponential, E, notation:

    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    import static java.lang.System.*;
    Pattern pattern = Pattern.compile("^[0-9]+\\.0{15}?|9{15}?[0-9]+E-?[0-9]+$");
    Matcher matcher = pattern.matcher("3.0E-4");
    boolean result = matcher.matches();
    out.println("Pattern match result: " + result + ".");

    I want to anchor to the left, have any number of integers 0-9, specify a decimal point . , then have either 15 zeroes or 15 nines, any one digit 0-9, the letter E, possibly a negative sign, 3 integers 0-9 and then anchor to the right.

    How do I update my regular expression pattern above, so that it will match Strings like "3.0E-4" and come back true
    with Strings like this, and more broadly, if you gather my intentions with what I wish to be matching to?
    Last edited by Zachary1234; February 22nd, 2023 at 09:29 PM.

Tags for this Thread

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