0

There is piece of code that replaces the C/o,d/o,s/o or w/o as below :

if (temp.contains(",,"))
    {
        temp=temp.replace ("C/O,,","");
        temp=temp.replace ("S/O,,","");
        temp=temp.replace ("D/O,,","");
        temp=temp.replace ("W/O,,","");
    }

But i want to replace above by regex so that it automatically removes C or S or D or W if there is a char sequence ",," I am not able to get what regex can be used . Please help.

jayendra bhatt
  • 1,337
  • 2
  • 19
  • 41
  • Possible duplicate of [Regex for C/O in address line](http://stackoverflow.com/questions/19505835/regex-for-c-o-in-address-line) – 2787184 Nov 30 '15 at 11:50

1 Answers1

2

You mean this?

temp=temp.replaceAll("[SDWC]/O,,","");

For case-insensitive match,

temp=temp.replaceAll("(?i)[SDWC]/O,,","");
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274