public static String CreateRegexFromString(String inString) {
StringBuilder newString = new StringBuilder();
for(int i=0; i<inString.length(); ++i) {
char eachCharacher = inString.charAt(i);
if ("\\.^$|?*+[]{}()".indexOf(eachCharacher) != -1)
newString.append('\\').append(eachCharacher);
else if (Character.isLetter(eachCharacher))
newString.append("["+Character.toLowerCase(eachCharacher)+Character.toUpperCase(eachCharacher)+"]");
else if (Character.isDigit(eachCharacher))
newString.append("\\d");
else
newString.append(eachCharacher);
}
return newString.toString();
}
StringBuilder newString = new StringBuilder();
for(int i=0; i<inString.length(); ++i) {
char eachCharacher = inString.charAt(i);
if ("\\.^$|?*+[]{}()".indexOf(eachCharacher) != -1)
newString.append('\\').append(eachCharacher);
else if (Character.isLetter(eachCharacher))
newString.append("["+Character.toLowerCase(eachCharacher)+Character.toUpperCase(eachCharacher)+"]");
else if (Character.isDigit(eachCharacher))
newString.append("\\d");
else
newString.append(eachCharacher);
}
return newString.toString();
}
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......