I am new to Regex.
I have data(String[] array) in address formart
example
105 MyOwn St, City, ON A1B 2C3, Canada
Sometimes i got it as
- MyOwn st, City, A1B 2C3, Canada
- City, A1B 2C3
- 105 MyOwn St, City, ON A1B 2C3
- City, ON A1B 2C3, Canada
I want the following result
Street: 105 MyOwn St or MyOwn st
City: City
Postal Code : A1B 2C3
Country : Canada
^ I have used if else to check if the string size. and used some methods to get my desired result.
I want to improve my functionality.
So, what i am going to do now is, create some regex patterns and use a switch statement.
so as, i am new to regex, i tried this pattern on my complete string it does match and give me a result in 4 groups, i tried it here (http://regexr.com/)
Pattern datePatt = Pattern.compile("^(\d+\s+[a-zA-z]+\s+\w+)[,](\s*[a-zA-Z]+)[,](\s+[a-z|A-Z]{2}\s+[a-zA-Z][0-9][a-zA-Z]\s*[0-9][a-zA-Z][0-9])[,](\s+[a-zA-Z]{6})$");
this pattern matches my string
But when i tried it in eclipse it gives me error
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
Aucun commentaire:
Enregistrer un commentaire