1 /*******************************************************************************
2 * Copyright 2017 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
13 ******************************************************************************/
14 package org.onap.msb.sdk.discovery.util;
16 import java.util.regex.Pattern;
18 public class RegExpTestUtil {
20 public static boolean serviceNameRegExpTest(String serviceName) {
22 String serviceNameReg = "^([0-9a-zA-Z]|-|_)*$";
23 return Pattern.matches(serviceNameReg, serviceName);
28 public static boolean hostRegExpTest(String host) {
30 String hostReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
31 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
32 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
33 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)" + ":(\\d{1,5})$";
34 return Pattern.matches(hostReg, host);
38 public static boolean ipRegExpTest(String ip) {
40 String hostReg = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
41 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
42 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
43 + "(00?\\d|1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
44 return Pattern.matches(hostReg, ip);
48 public static boolean portRegExpTest(String port) {
50 String hostReg = "^\\d{1,5}$";
51 return Pattern.matches(hostReg, port);
55 public static boolean versionRegExpTest(String version) {
57 String versionReg = "^v\\d+(\\.\\d+)?$";
58 return Pattern.matches(versionReg, version);
62 public static boolean urlRegExpTest(String url) {
65 String urlReg = "^\\/.*((?!\\/).)$";
66 return Pattern.matches(urlReg, url);
72 public static void main(String[] args) {
73 System.out.println(urlRegExpTest("/"));