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
// Examine text looking for matches | |
WORD_REGEX.findAll(text) | |
.forEach { match -> | |
// Define range of inner letters | |
val range: IntRange = | |
match.range.first + 1 | |
until match.range.last | |
// ... shuffling stuff ... | |
} |
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
// Examine text looking for matches | |
WORD_REGEX.matcher(text).results() | |
.forEach(match -> { | |
// Second letter | |
final var start = match.start() + 1; | |
// Penultimate letter | |
final var end = match.end() - 1; | |
final var length = end - start; | |
// ... shuffling stuff ... | |
} |
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
\p{IsLatin}(\p{IsLatin})\1*(?!\1)\p{IsLatin}\p{IsLatin}+ |
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
package wscrambler | |
object WordScrambler { | |
private val WORD_REGEX = | |
"""\p{IsLatin}(\p{IsLatin})\1*(?!\1)\p{IsLatin}\p{IsLatin}+""".toRegex() | |
@JvmStatic // JVM static method | |
// CLI FQN: wscrambler.Scrambler | |
fun main(args: Array<String>) { |