Java; String replace (using regular expressions)?
As part of a project for school, I need to replace a string from the form:
5 * x^3 - 6 * x^1 + 1
to something like:
5x<sup>3</sup> - 6x<sup>1</sup> + 1
I believe this can be done with regular expressions, but I don't know how to do it yet.
Can you lend me a hand?
P.S. The actual assignment is to implement a Polynomial Processing Java application, and I'm using this to pass polynomial.toString() from the model to the view, and I want do display it using html tags in a pretty way.
str.replaceAll("\\^([0-9]+)", "<sup>$1</sup>");
private String removeScript(String content) {
Pattern p = Pattern.compile("<script[^>]*>(.*?)</script>",
Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
return p.matcher(content).replaceAll("");
}
String input = "hello I'm a java dev" +
"no job experience needed" +
"senior software engineer" +
"java job available for senior software engineer";
String fixedInput = input.replaceAll("(java|job|senior)", "<b>$1</b>");