Results 1 to 10 of 10
- 11-21-2012, 10:12 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Regular Expression that displays locale information
I have 2 questions based on Regular expressions, and I'm stuck through the second.
I'm confused as to where to even start.2) Write a regular expression that displays only the following Locale information from all the available Locales. The information shows the displayname, a three-letter abbreviation for the locale's country and a three-letter abbreviation for the locale's language. Your program should verify your regular expression by printing out the information below.
English (Malta),MLT,eng
French (Belgium),BEL,fra
French (Canada),CAN,fra
French (Switzerland),CHE,fra
English (Philippines),PHL,eng
English (Ireland),IRL,eng
French (Luxembourg),LUX,fra
English (India),IND,eng
English (Australia),AUS,eng
French (France),FRA,fra
English (Canada),CAN,eng
English (Singapore),SGP,eng
Question 1 required me to write a regular expression matching all the variations of my name, and asking the user to enter a string and testing if it matches; which I managed to complete.
- 11-21-2012, 11:03 PM #2
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Re: Regular Expression that displays locale information
EDIT: After a long search I'm guessing I need something along the lines of:
Java Code:Locale[] locales = Calendar.getAvailableLocales(); for(Locale l: locales) { if (l.matches("English|French.*) System.out.println(l); }
- 11-22-2012, 07:03 PM #3
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Re: Regular Expression that displays locale information
Any help please? It would be really appreciated :/
- 11-23-2012, 05:18 PM #4
Re: Regular Expression that displays locale information
The list of locales you displayed, is that the input or the desired output?
- 11-23-2012, 11:17 PM #5
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
- 11-24-2012, 01:27 AM #6
Re: Regular Expression that displays locale information
So, what does the input look like?
- 11-24-2012, 04:49 PM #7
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Re: Regular Expression that displays locale information
- 11-24-2012, 04:58 PM #8
Re: Regular Expression that displays locale information
Have you gone through the API for the Locale class? Which methods do you see that would be useful in obtaining the inputs for your regex?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-10-2012, 12:52 AM #9
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Re: Regular Expression that displays locale information
The input for all the available locales is:
so I need to use a regular expression to sort through those lists and only display the locales that match these:Java Code:Locale locs[] = Locale.getAvailableLocales(); for (Locale loc: locs) { System.out.print(loc.getDisplayName() + ","); System.out.print(loc.getISO3Country() + ","); System.out.println(loc.getISO3Language()); }
Currently displays:English (Malta),MLT,eng
French (Belgium),BEL,fra
French (Canada),CAN,fra
French (Switzerland),CHE,fra
English (Philippines),PHL,eng
English (Ireland),IRL,eng
French (Luxembourg),LUX,fra
English (India),IND,eng
English (Australia),AUS,eng
French (France),FRA,fra
English (Canada),CAN,eng
English (Singapore),SGP,eng
Malay (Malaysia),MYS,msa
Arabic (Qatar),QAT,ara
Icelandic (Iceland),ISL,isl
Finnish (Finland),FIN,fin
Polish,,pol
English (Malta),MLT,eng
Italian (Switzerland),CHE,ita
Dutch (Belgium),BEL,nld
Arabic (Saudi Arabia),SAU,ara
Arabic (Iraq),IRQ,ara
Spanish (Puerto Rico),PRI,spa
Spanish (Chile),CHL,spa
Finnish,,fin
German (Austria),AUT,deu
Danish,,dan
English (United Kingdom),GBR,eng
Spanish (Panama),PAN,spa
Serbian,,srp
Arabic (Yemen),YEM,ara
Macedonian (Macedonia),MKD,mkd
......
- 12-13-2012, 10:41 PM #10
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Re: Regular Expression that displays locale information
In the very rare case that someone actually wondered what the answer was, I got there in the end:
Java Code:public static void matchlocales() { Locale locs[] = Locale.getAvailableLocales(); for (Locale loc: locs) { if ((loc.getDisplayName().matches("English.[^UN]*|French.[^,]*")) && (loc.getISO3Country().matches("[^Z].*"))) { System.out.print(loc.getDisplayName() + ","); System.out.print(loc.getISO3Country() + ","); System.out.println(loc.getISO3Language()); } } }
Similar Threads
-
Regular expression
By Krik in forum New To JavaReplies: 3Last Post: 10-26-2012, 05:06 PM -
Regular expression
By garnaout in forum New To JavaReplies: 4Last Post: 05-15-2012, 06:22 PM -
Problem reading Locale information on MAC Internationalization issue
By rjalori in forum AWT / SwingReplies: 2Last Post: 07-26-2011, 07:48 AM -
Regular Expression Help
By niketanand in forum Advanced JavaReplies: 1Last Post: 06-24-2011, 04:56 PM -
Help with regular expression
By mr.ab18 in forum New To JavaReplies: 2Last Post: 08-06-2010, 10:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks