The regex-native way for commenting is using the /x
(free spacing or extended mode) flag.
In many languages there is support for multiline strings, so your regular expression will look like:
regex = /\b # Begin match at the word boundary(whitespace boundary)
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{4} # Match four digits
\b # End match at the word boundary(whitespace boundary)
/x
In java, however, there is still no way to do this this, so you can either comment it as you did, or otherwise carefully construct your string with \n
between each line:
String regex = "\\b # Begin match at the word boundary(whitespace boundary)\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{4} # Match four digits\n" +
"\\b # End match at the word boundary(whitespace boundary)";
// Of course, you need to compile with `Pattern.COMMENTS`
Pattern pattern = Pattern.compile(regex, Pattern.COMMENTS);
if (pattern.matcher(args[0]).matches()) {
System.out.println("Match!");
} else {
System.out.println("No match.");
}
The above has no advantage to your suggestion on how to comment your regex, so I guess it a matter of taste...
The regex-native way for commenting is using the /x
(free spacing or extended mode) flag.
In many languages there is support for multiline strings, so your regular expression will look like:
regex = /\b # Begin match at the word boundary(whitespace boundary)
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{4} # Match four digits
\b # End match at the word boundary(whitespace boundary)
/x
In java, however, there is still no way to do this, so you can either comment it as you did, or otherwise carefully construct your string with \n
between each line:
String regex = "\\b # Begin match at the word boundary(whitespace boundary)\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{4} # Match four digits\n" +
"\\b # End match at the word boundary(whitespace boundary)";
// Of course, you need to compile with `Pattern.COMMENTS`
Pattern pattern = Pattern.compile(regex, Pattern.COMMENTS);
if (pattern.matcher(args[0]).matches()) {
System.out.println("Match!");
} else {
System.out.println("No match.");
}
The above has no advantage to your suggestion on how to comment your regex, so I guess it a matter of taste...
The regex-native way for commenting is using the /x
(free spacing or extended mode) flag.
In many languages there is support for multiline strings, so your regular expression will look like:
regex = /\b # Begin match at the word boundary(whitespace boundary)
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{4} # Match four digits
\b # End match at the word boundary(whitespace boundary)
/x
In java, however, there is still no way to do this, so you can either comment it as you did, or otherwise carefully construct your string with \n
between each line:
String regex = "\\b # Begin match at the word boundary(whitespace boundary)\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{4} # Match four digits\n" +
"\\b # End match at the word boundary(whitespace boundary)";
// Of course, you need to compile with `Pattern.COMMENTS`
Pattern pattern = Pattern.compile(regex, Pattern.COMMENTS);
if (pattern.matcher(args[0]).matches()) {
System.out.println("Match!");
} else {
System.out.println("No match.");
}
The above has no advantage to your suggestion on how to comment your regex, so I guess it a matter of taste...
The regex-native way for commenting is using the /x
(free spacing or extended mode) flag.
In many languages there is support for multiline strings, so your regular expression will look like:
regex = /\b # Begin match at the word boundary(whitespace boundary)
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{4} # Match four digits
\b # End match at the word boundary(whitespace boundary)
/x
In java, however, there is still no way to do this, so you can either comment it as you did, or otherwise carefully construct your string with \n
between each line:
String regex = "\\b # Begin match at the word boundary(whitespace boundary)\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{4} # Match four digits\n" +
"\\b # End match at the word boundary(whitespace boundary)";
#// ofOf course, you need to compile with `Pattern.COMMENTS`
Pattern pattern = Pattern.compile(regex, Pattern.COMMENTS);
if (pattern.matcher(args[0]).matches()) {
System.out.println("Match!");
} else {
System.out.println("No match.");
}
The above has no advantage to your suggestion on how to comment your regex, so I guess it a matter of taste...
The regex-native way for commenting is using the /x
(free spacing or extended mode) flag.
In many languages there is support for multiline strings, so your regular expression will look like:
regex = /\b # Begin match at the word boundary(whitespace boundary)
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{4} # Match four digits
\b # End match at the word boundary(whitespace boundary)
/x
In java, however, there is still no way to do this, so you can either comment it as you did, or otherwise carefully construct your string with \n
between each line:
String regex = "\\b # Begin match at the word boundary(whitespace boundary)\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{4} # Match four digits\n" +
"\\b # End match at the word boundary(whitespace boundary)";
# of course, you need to compile with `Pattern.COMMENTS`
Pattern pattern = Pattern.compile(regex, Pattern.COMMENTS);
if (pattern.matcher(args[0]).matches()) {
System.out.println("Match!");
} else {
System.out.println("No match.");
}
The above has no advantage to your suggestion on how to comment your regex, so I guess it a matter of taste...
The regex-native way for commenting is using the /x
(free spacing or extended mode) flag.
In many languages there is support for multiline strings, so your regular expression will look like:
regex = /\b # Begin match at the word boundary(whitespace boundary)
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{4} # Match four digits
\b # End match at the word boundary(whitespace boundary)
/x
In java, however, there is still no way to do this, so you can either comment it as you did, or otherwise carefully construct your string with \n
between each line:
String regex = "\\b # Begin match at the word boundary(whitespace boundary)\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{4} # Match four digits\n" +
"\\b # End match at the word boundary(whitespace boundary)";
// Of course, you need to compile with `Pattern.COMMENTS`
Pattern pattern = Pattern.compile(regex, Pattern.COMMENTS);
if (pattern.matcher(args[0]).matches()) {
System.out.println("Match!");
} else {
System.out.println("No match.");
}
The above has no advantage to your suggestion on how to comment your regex, so I guess it a matter of taste...
The regex-native way for commenting is using the /x
(free spacing or extended mode) flag.
In many languages there is support for multiline strings, so your regular expression will look like:
regex = /\b # Begin match at the word boundary(whitespace boundary)
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{4} # Match four digits
\b # End match at the word boundary(whitespace boundary)
/x
In java, however, there is still no way to do this, so you can either comment it as you did, or otherwise carefully construct your string with \n
between each line:
String regex = "\\b # Begin match at the word boundary(whitespace boundary)\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{4} # Match four digits\n" +
"\\b # End match at the word boundary(whitespace boundary)";
# of course, you need to compile with `Pattern.COMMENTS`
Pattern pattern = Pattern.compile(regex, Pattern.COMMENTS);
if (pattern.matcher(args[0]).matches()) {
System.out.println("Match!");
} else {
System.out.println("No match.");
}
The above has no advantage to your suggestion on how to comment your regex, so I guess it a matter of taste...
The regex-native way for commenting is using the /x
(free spacing or extended mode) flag.
In many languages there is support for multiline strings, so your regular expression will look like:
regex = /\b # Begin match at the word boundary(whitespace boundary)
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{4} # Match four digits
\b # End match at the word boundary(whitespace boundary)
/x
In java, however, there is still no way to do this, so you can either comment it as you did, or otherwise carefully construct your string with \n
between each line:
String regex = "\\b # Begin match at the word boundary(whitespace boundary)\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{4} # Match four digits\n" +
"\\b # End match at the word boundary(whitespace boundary)";
The above has no advantage to your suggestion on how to comment your regex, so I guess it a matter of taste...
The regex-native way for commenting is using the /x
(free spacing or extended mode) flag.
In many languages there is support for multiline strings, so your regular expression will look like:
regex = /\b # Begin match at the word boundary(whitespace boundary)
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{3} # Match three digits
[-.]? # Optional - Match dash or dot
\d{4} # Match four digits
\b # End match at the word boundary(whitespace boundary)
/x
In java, however, there is still no way to do this, so you can either comment it as you did, or otherwise carefully construct your string with \n
between each line:
String regex = "\\b # Begin match at the word boundary(whitespace boundary)\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{3} # Match three digits\n" +
"[-.]? # Optional - Match dash or dot\n" +
"\\d{4} # Match four digits\n" +
"\\b # End match at the word boundary(whitespace boundary)";
# of course, you need to compile with `Pattern.COMMENTS`
Pattern pattern = Pattern.compile(regex, Pattern.COMMENTS);
if (pattern.matcher(args[0]).matches()) {
System.out.println("Match!");
} else {
System.out.println("No match.");
}
The above has no advantage to your suggestion on how to comment your regex, so I guess it a matter of taste...