Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default A Simple Regular Expression...

    Hey, im new to RegEx. Lets suppose I have the following:

    import java.util.regex.*;
    public class RegexValidation {
    public static void main (String[]args){
    String RE1="\\+?[0-9]* ?(\\(0\\))?[0-9. ]{7,}";
    String RE2="\\w[-.\\w]*@\\w[-\\w]*\\.\\w[-.\\w]*";
    String RE3="\\w[-,. \\w]*";
    String RE4="[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][A-Z-[CIKMOV]]{2}";

    //code here...?
    }
    }

    I need to validate these contact details using the regular expressions int he String's. The question is:

    content-manager@bradford.ac.uk
    University of Bradford
    Bradford, West Yorkshire
    BD7 1DP
    UK
    +44 (0)1274 232323

    (i) Find the number of matches for each of the regular expressions RE1-4, taking as input-strings whole lines in the contact details given above.

    (ii) Suggest how to rename the regular expressions RE1-4 to indicate which details they validate, e.g. rename RE3 to EMAIL_RE (check!).

    If you could please help me out, would be kind of you. Thank you :)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: A Simple Regular Expression...

    on the first question of writing code:

    (i) Find the number of matches for each of the regular expressions RE1-4, taking as input-strings whole lines in the contact details given above.
    Firstly, what is "RE1-4" ?

  4. #4
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: A Simple Regular Expression...

    Reference variables of String type.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: A Simple Regular Expression...

    Quote Originally Posted by diamonddragon View Post
    Reference variables of String type.
    Meaning what exactly? I'm not sure how this relates to the original question.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: A Simple Regular Expression...

    Quote Originally Posted by mrashi12 View Post
    on the first question of writing code:

    (i) Find the number of matches for each of the regular expressions RE1-4, taking as input-strings whole lines in the contact details given above.
    Firstly, what is "RE1-4" ?
    RE1-4 refers to the 4 String constants that are to be used as regular expressions, RE1, RE2, RE3, and RE4. You're to use them to validate the input.

  7. #7
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: A Simple Regular Expression...

    ok I misread "each" lol, and how do I now actually find the number of matches for each of these regular expressions taken as input strings whole lines in the following contacts:
    content-manager@bradford.ac.uk
    University of Bradford
    Bradford, West Yorkshire
    BD7 1DP
    UK
    +44 (0)1274 232323

    and also how would I rename the regular expressions RE1-4 to indicate which details they validate please?

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: A Simple Regular Expression...

    Quote Originally Posted by mrashi12 View Post
    ok I misread "each" lol, and how do I now actually find the number of matches for each of these regular expressions taken as input strings whole lines in the following contacts:
    The Java regular expressions tutorials shows you how to use a while loop to iterate through and "find()" each match.

    and also how would I rename the regular expressions RE1-4 to indicate which details they validate please?
    First do the first part of the assignment to see what each regex matches. Then use that information to rename them.

  9. #9
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: A Simple Regular Expression...

    Thank you very much!

  10. #10
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: A Simple Regular Expression...

    Quote Originally Posted by Fubarable View Post
    Meaning what exactly? I'm not sure how this relates to the original question.
    Well I'm trying to inspire OP rather than giving full answer.

    P.S. What does OP mean?

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: A Simple Regular Expression...

    @diamonddragon:
    OP means "original poster" or the "original post".

    @mrashi12:
    You're welcome!

Similar Threads

  1. regular expression
    By ehsansad in forum New To Java
    Replies: 8
    Last Post: 03-18-2011, 03:23 PM
  2. Help with regular expression
    By mr.ab18 in forum New To Java
    Replies: 2
    Last Post: 08-06-2010, 11:01 PM
  3. regular expression
    By prof.deedee in forum JDBC
    Replies: 3
    Last Post: 02-19-2010, 12:15 PM
  4. regular expression
    By QkrspCmptPop in forum Advanced Java
    Replies: 8
    Last Post: 01-20-2010, 04:55 AM
  5. regular expression
    By ras_pari in forum Advanced Java
    Replies: 27
    Last Post: 10-07-2009, 01:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •