Problem statement:
can you remove the special character from a string using regex in java?
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RemoveSpecialCharacter{
public static void main(String args[]){
String c = "p$82-a/*@#^&873";
Pattern pt = Pattern.compile("^a-zA-Z0-9");
Matcher match = pt.matcher(c);
while(match.find()){
String s = match.group();
c = c.replaceAll("\\"+s, "");
}
System.out.println(c);
}
}
Output:
p82a873
can you remove the special character from a string using regex in java?
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RemoveSpecialCharacter{
public static void main(String args[]){
String c = "p$82-a/*@#^&873";
Pattern pt = Pattern.compile("^a-zA-Z0-9");
Matcher match = pt.matcher(c);
while(match.find()){
String s = match.group();
c = c.replaceAll("\\"+s, "");
}
System.out.println(c);
}
}
Output:
p82a873
No comments:
Post a Comment