All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.unibo.tuprolog.ui.gui.RegexExtensions.kt Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.ui.gui

infix fun Regex.or(other: Regex): Regex = anyOf(this, other)

infix fun Regex.and(other: Regex): Regex = Regex(pattern + other.pattern)

fun anyOf(vararg regexps: Regex): Regex = anyOf(sequenceOf(*regexps))

fun anyOf(regexps: Iterable): Regex = anyOf(regexps.asSequence())

fun anyOf(regexps: Sequence): Regex = regexps.map { it.pattern }.joinToString("|").toRegex()

fun Regex.asGroup(name: String? = null): Regex =
    if (name == null) {
        "($pattern)"
    } else {
        "(?<$name>$pattern)"
    }.toRegex()

fun wordOf(pattern: String): Regex = wordify(pattern).toRegex()

fun wordify(pattern: String): String = "(^|\\b)($pattern)(\\b|$)"

fun Regex.asWord(): Regex = wordOf(pattern)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy