Search code examples
javaregexreplaceall

replaceall REGEX in java


Completely new to java and I have been playing around with regex in a replaceAll command and wondered if the way that I have done it is the best way? I basically wanted to find every occurence of <Letter_File TIMESTAMP="0000-00-00 00:00" FILECREATOR="XXX" BRAND_ID="0" BRAND_NAME="xxxxxxxxx"> within 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 the best way of doing the function or is there a way that the REGEX can be shortened?

Any feedback is more then welcome.

Thanks


Solution

  • How about:

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