Matching Zip code using regular expression
This Example describes the way of matching Zip code with the regular expression .For this we are going to make program named Matching_Zipcode.java. The steps involved in program Matching_Zipcode.java are described below:-
String zipCode = "\\d{5}(-\\d{4})?":-This is the regular expression use to match with Zip code.
matchZip("45643-44435"):-Defining Zip code which is to be matched with the regular expression
Matching_Zipcode.java
|
Output of the program:-
MATCH : Zip code is :45643 regex for the Zip code is : \d{5}(-\d{4})? NO MATCH: Zip code is:45643-44435 regex for the Zip code is: \d{5}(-\d{4})? |