/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
String prep
= "{b} this {/b} is \\{b} a **fully** ***featured * test** *of* __my__ ~~thing~~" + "~~yes__it~~is__";
String out
= convertFormatting
(prep
); System.
out.
println("the previous line is supposed to look like this:"); System.
out.
println("\\{b} this \\{/b} is \\\\{b} a {b}fully{/b} " + "{b}{i}featured {/i} test{/b} {i}of{/i} {u}my{/u} {s}thing{/s}" +
"{s}yes{u}it{/s}is{/u}");
// your code goes here
}
Pattern bold = Pattern.compile("(?<!\\\\)\\*\\*(([^*]|\\*(?!\\*))+)?\\*\\*");
Pattern underline = Pattern.compile("(?<!\\\\)__(([^_]|_(?!_))+)?__");
Pattern italics = Pattern.compile("(?<!\\\\)\\*([^\\*]+?)\\*|_([^_]+?)_");//DO NOT RUN THIS ONE BEFORE RUNNING BOTH BOLD AND UNDERLINE
Pattern strike = Pattern.compile("(?<!\\\\)~~(([^~]|~(?!~))+)?~~");
Pattern prep = Pattern.compile("(\\{([bius]|\\/[bius])})");
Matcher m = prep.matcher(input);
if(m.find()) {
input = m.replaceAll("\\\\$1");
}
m = bold.matcher(input);
if(m.find()) {
input = m.replaceAll("{b}$1{/b}");
}
m = underline.matcher(input);
if(m.find()) {
input = m.replaceAll("{u}$1{/u}");
}
m = strike.matcher(input);
if(m.find()) {
input = m.replaceAll("{s}$1{/s}");
}
m = italics.matcher(input);
if(m.find()) {
input = m.replaceAll("{i}$1{/i}");
}
output = input;//comment this out before you push an update, smartass
return output;
}
}