This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// One backslash | |
"""\p{InLatin}{4,}""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Two backslashes | |
"""\\p{InLatin}{4,}""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun String.toRegex() = | |
Regex(Pattern.compile(this)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun String.toRegex(): Regex { | |
return Regex(Pattern.compile(this)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val wordRegex = | |
"""\p{InLatin}{4,}""".toRegex() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final var wordRegex = | |
Pattern.compile("\\p{InLatin}{4,}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import java.util.regex.*; | |
import java.util.stream.*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Collect readers from args/stdin | |
final Stream<BufferedReader> readers; | |
if (args.length > 0) { | |
readers = Arrays.stream(args) | |
.map(filename -> { | |
try { | |
return new BufferedReader( | |
new FileReader(filename)); | |
} catch (Exception e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Collect readers from args/stdin | |
val readers = | |
if (args.isNotEmpty()) | |
args.map { File(it).reader() } | |
else | |
listOf(System.`in`.reader()) | |
// Swallow all readers into one string | |
val content = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final var reader = | |
new InputStreamReader( | |
new FileInputStream( | |
new File(filename))); |