Replaceall REGEX in java

Completely new to java and I was playing around with regex in the replaceAll command and was wondering if the best way I have done this? I basically wanted to find each <Letter_File TIMESTAMP="0000-00-00 00:00" FILECREATOR="XXX" BRAND_ID="0" BRAND_NAME="xxxxxxxxx">

in my file and replace it with <Letter_File>

I am using the following:

str1 = str1.replaceAll("\\<Letter\\_File[a-zA-Z\\_\\s\\=\\\"0-9-\\:\\\"]+\\>","<Letter_File>");>

What I wanted to know is this is the best way to do the function or is there a way that REGEX can be shortened?

Any feedback is more appreciated.

thank

+3


source to share


1 answer


What about:



str1 = str1.replaceAll("<Letter_File[^>]+>","<Letter_File>");>

      

+3


source







All Articles