megha raina
megha raina

Reputation: 29

Regex pattern for ^A

I need to remove ^A from an incoming string, I'm looking for a regex pattern for it

Don’t want to use \\p{cntrl} , I don’t want to delete the other control characters coming in the string

Upvotes: 0

Views: 65

Answers (2)

Aaron
Aaron

Reputation: 24812

I suggest you avoid using regex and instead use basic string manipulation :

String toRemove = "^A";
yourString.replace(toRemove, "");

You can try it here.

Be careful not to use String methods that work on regexs, especially since the name of the methods aren't very informative (replace replaces all occurences of a fixed string, replaceAll replaces all occurences that match a regex pattern).

Upvotes: 0

i.bondarenko
i.bondarenko

Reputation: 3572

You should use escaping for '^A':

public static void main(String[] args) {
    String value = "remove special char ^A A and B";
    System.out.println(value.replaceAll("\\^A", ""));
}

Output:

remove special char A and B

Upvotes: 1

Related Questions