A question about an article appeared in Oracle Blog by the title "Text Blocks Come to Java"

Karim Ourrai karim.ourrai at gmail.com
Wed Oct 30 15:50:01 UTC 2019


Hello everyone.
I have a question about an article written by Mala Gupta in the Oracle Blog about "Text Blocks Come to Java"
https://blogs.oracle.com/javamagazine/text-blocks-come-to-java
In the section Ease of Working with Multiline Values
She wrote this
A regex usually includes many special characters. When you wrote one as a String value prior to Java 13, you needed to escape some of those special characters—making it difficult to write, read, or understand such expressions. Here’s an example, prior to text blocks, which stores the regex [0-9]{3}\-[0-9]{4}:
String java12OrBeforeRegex = "[0-9]{3}\\t-[0-9]{4}";
With text blocks, you can define the same regex as follows:
String java13Regex = """
[0-9]{3}\t-[0-9]{4}""";
I couldn’t find anything about this in https://openjdk.java.net/jeps/355
Because in the third section it said 
 any escape sequences in the content are interpreted. 
Wouldn’t that means that java13Regex should be wrtten like this
String java13Regex = """
[0-9]{3}\\t-[0-9]{4}""";

Best regards


More information about the amber-dev mailing list