Results 1 to 11 of 11
Thread: A Simple Regular Expression...
- 01-30-2012, 12:02 AM #1
`
- Join Date
- Dec 2011
- Posts
- 7
- Rep Power
- 0
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 :)
-
Re: A Simple Regular Expression...
Help you out -- how? You haven't told us where exactly you're stuck.
- 01-30-2012, 12:20 AM #3
`
- Join Date
- Dec 2011
- Posts
- 7
- Rep Power
- 0
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" ?
- 01-30-2012, 12:23 AM #4
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
Re: A Simple Regular Expression...
Reference variables of String type.
-
Re: A Simple Regular Expression...
-
Re: A Simple Regular Expression...
- 01-30-2012, 12:31 AM #7
`
- Join Date
- Dec 2011
- Posts
- 7
- Rep Power
- 0
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?
-
Re: A Simple Regular Expression...
The Java regular expressions tutorials shows you how to use a while loop to iterate through and "find()" each match.
First do the first part of the assignment to see what each regex matches. Then use that information to rename them.and also how would I rename the regular expressions RE1-4 to indicate which details they validate please?
- 01-30-2012, 12:37 AM #9
`
- Join Date
- Dec 2011
- Posts
- 7
- Rep Power
- 0
Re: A Simple Regular Expression...
Thank you very much!
- 01-30-2012, 12:43 AM #10
Senior Member
- Join Date
- Jan 2012
- Posts
- 210
- Rep Power
- 2
-
Similar Threads
-
regular expression
By ehsansad in forum New To JavaReplies: 8Last Post: 03-18-2011, 02:23 PM -
Help with regular expression
By mr.ab18 in forum New To JavaReplies: 2Last Post: 08-06-2010, 10:01 PM -
regular expression
By prof.deedee in forum JDBCReplies: 3Last Post: 02-19-2010, 11:15 AM -
regular expression
By QkrspCmptPop in forum Advanced JavaReplies: 8Last Post: 01-20-2010, 03:55 AM -
regular expression
By ras_pari in forum Advanced JavaReplies: 27Last Post: 10-07-2009, 12:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks