+ Reply to Thread
Results 1 to 3 of 3

Thread: using Regular Expressions

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    22

    using Regular Expressions

    I am trying to use regular expression to find numbers that accepts all numbers that contain 1 and 5 (in any order) and send a boolean value of true when found , but i got no luck with that .

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    13
    You actually don`t need regex , you can use a simple function like below :
    Code:
    public static boolean containsDigit(int n, int digit) {
        return String.valueOf(n).contains(String.valueOf(digit));
    }
    
    int n = 12345678;
    boolean nContains3And7 = containsDigit(n, 1) && containsDigit(n, 5);

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    22
    Thank you it worked , it seems that i choose the hard way first

+ Reply to Thread

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