import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(^[%@]\\tfor\\t)(.*[\\w\\s:]??)(?![→←].*)(\\[sound.*)";
final String string = "% for 1 <i><font color=\"#ab0000\">British English</font></i> to make something seem less successful, interesting, good etc than it really is: [sound:_p008-000614203.mp3] the pessimists who are talking down Britain →贬低英国的悲观主义者 \n"
+ "@ for to talk to someone as if they are stupid, although they are not ←以高人一等的口气对〔某人〕说话; <i><font color=\"#efefef\" style=\"background-color: rgb(141, 141, 141);\">SYN</font></i> patronize: [sound:_p008-000614218.mp3] The students felt that they were talked down to as though they were children. →这些学生感到和他们说话的都是一副居高临下的口气,好像他们是小孩一样。 \n"
+ "@ for talk somebody into doing something [sound:_p008-000614234.mp3] My husband talked me into going skiing. →我的丈夫说服我去滑雪。 \n";
final String subst = "\\1\\2\\t\\3";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html