Regular expression DSL on Kotlin

Related tags

Kotlin RegExp-DSL
Overview

Examples

Characters

Construct Equivalent Matches
x character(Char) The character x
\\ character('\\') The backslash character
\0n octal(OctalValue(7)) The character with octal value 0n (0 <= n <= 7)
\0nn octal(OctalValue(7, 7)) The character with octal value 0nn (0 <= n <= 7)
\0mnn octal(OctalValue(3, 7, 7)) The character with octal value 0mnn (0 <= m <= 3, 0 <= n <= 7)
\xhh hexdecimal(HexdecimalValue('F', 'F')) The character with hexadecimal value 0xhh
\uhhhh unicode(UnicodeValue('F', 'F', 'F', 'F')) The character with hexadecimal value 0xhhhh
\t tab() The tab character ('\u0009')
\n newLine() The newline (line feed) character ('\u000A')
\r carriageReturn() The carriage-return character ('\u000D')
\f formFeed() The form-feed character ('\u000C')
\a alert() The alert (bell) character ('\u0007')
\e escape() The escape character ('\u001B')
\cx control(Char) The control character corresponding to x
string(String) The character sequence

Character classes

Construct Equivalent Matches
[abc] characterClass(Boolean(false), CharacterClassBuilder.()->Unit){...} a, b, or c (simple class)
[^abc] characterClass(Boolean(true), CharacterClassBuilder.()->Unit){...} Any character except a, b, or c (negation)
[a-zA-Z] characterClass(Boolean(false), CharacterClassBuilder.()->Unit){range('a', 'z') …} a through z or A through Z, inclusive (range)
[a-d[m-p]] characterClass(Boolean(false), CharacterClassBuilder.()->Unit){… characterClass{...}} a through d, or m through p: [a-dm-p] (union)
[a-z&&[def]] characterClass(Boolean(false), CharacterClassBuilder.()->Unit){… intersection(Boolean(false), CharacterClassBuilder.()->Unit){…}} d, e, or f (intersection)
[a-z&&[^bc]] characterClass(Boolean(false), CharacterClassBuilder.()->Unit){… intersection(Boolean(true), CharacterClassBuilder.()->Unit){…}} a through z, except for b and c: [ad-z] (subtraction)

Predefined character classes

Construct Equivalent Matches
. anyCharacter() Any character (may or may not match line terminators)
\d digit() A digit: [0-9]
\D nonDigit() A non-digit: [^0-9]
\h horizontalWhitespaceCharacter() A horizontal whitespace character: [ \t\xA0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000]
\H nonHorizontalWhitespaceCharacter() A non-horizontal whitespace character: [^\h]
\s whitespaceCharacter() A whitespace character: [ \t\n\x0B\f\r]
\S noneWhitespaceCharacter() A non-whitespace character: [^\s]
\v verticalWhitespaceCharacter() A vertical whitespace character: [\n\x0B\f\r\x85\u2028\u2029]
\V noneVerticalWhitespaceCharacter() A non-vertical whitespace character: [^\v]
\w wordCharacter() A word character: [a-zA-Z_0-9]
\W noneWordCharacter() A non-word character: [^\w]

POSIX character classes (US-ASCII only)

Construct Equivalent Matches
\p{Lower} pLowerCase() A lower-case alphabetic character: [a-z]
\p{Upper} pUpperCase() An upper-case alphabetic character:[A-Z]
\p{ASCII} pASCII() All ASCII:[\x00-\x7F]
\p{Alpha} pAlphabetic() An alphabetic character:[\p{Lower}\p{Upper}]
\p{Digit} pDecimalDigit() A decimal digit: [0-9]
\p{Alnum} pAlphanumeric() An alphanumeric character:[\p{Alpha}\p{Digit}]
\p{Punct} pPunctuation() Punctuation: One of !"#$%&'()*+,-./:;<=>?@[]^_`{|}~
\p{Graph} pVisible() A visible character: [\p{Alnum}\p{Punct}]
\p{Print} pPrintable() A printable character: [\p{Graph}\x20]
\p{Blank} pSpaceOrTab() A space or a tab: [ \t]
\p{Cntrl} pControl() A control character: [\x00-\x1F\x7F]
\p{XDigit} pHexadecimal() A hexadecimal digit: [0-9a-fA-F]
\p{Space} pWhitespaceCharacter() A whitespace character: [ \t\n\x0B\f\r]

java.lang.Character classes (simple java character type)

Construct Equivalent Matches
\p{javaLowerCase} pjLowerCase() Equivalent to java.lang.Character.isLowerCase()
\p{javaUpperCase} pjUpperCase() Equivalent to java.lang.Character.isUpperCase()
\p{javaWhitespace} pjWhitespace() Equivalent to java.lang.Character.isWhitespace()
\p{javaMirrored} pjMirrored() Equivalent to java.lang.Character.isMirrored()

Classes for Unicode scripts, blocks, categories and binary properties

Construct Equivalent Matches
\p{IsLatin} pLatin() A Latin script character (script)
\p{InGreek} pGreek() A character in the Greek block (block)
\p{Lu} pUpperCaseCategory() An uppercase letter (category)
\p{IsAlphabetic} pAlphabeticBP() An alphabetic character (binary property)
\p{Sc} pCurrencySymbol() A currency symbol
\P{InGreek} pExceptGreek() Any character except one in the Greek block (negation)
\p{L} pAnyLetter() Any letter

Boundary matchers

Construct Equivalent Matches
^ beginLine() The beginning of a line
$ endLine() The end of a line
\b wordBoundary() A word boundary
\B noneWordBoundary() A non-word boundary
\A beginInput() The beginning of the input
\G endPreviousMatch() The end of the previous match
\Z endInputForFinalTerminator() The end of the input but for the final terminator, if any
\z endInput() The end of the input

Linebreak matcher

Construct Equivalent Matches
\R unicodeLinebreak() Any Unicode linebreak sequence, is equivalent to \u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029]

Quantifiers

Construct Equivalent Matches
X? missingOrOne() X, once or not at all
X* missingOrMore() X, zero or more times
X+ oneOrMore() X, one or more times
X{n} nExactly(Int) X, exactly n times
X{n,} nOrMore(Int) X, at least n times
X{n,m} nToM(Int, Int) X, at least n but not more than m times

Logical operators

Construct Equivalent Matches
X|Y or() Either X or Y
(X) group(RegexBuilder.()->Unit){...} X, as a capturing group

Back references

Construct Equivalent Matches
\k<name> namedCapturingGroupReference(String) Whatever the named-capturing group "name" matched

Quotation

Construct Equivalent Matches
\Q startQuoting() Nothing, but quotes all characters until \E
\E endQuoting() Nothing, but ends quoting started by \Q

Special constructs (named-capturing and non-capturing)

Construct Equivalent Matches
(?<name>X) namedCapturingGroup(String, RegexBuilder.()->Unit){} X, as a named-capturing group
(?:X) nonCapturingGroup(String, RegexBuilder.()->Unit){} X, as a non-capturing group
(?=X) positiveLookAhead(RegexBuilder.()->Unit){} X, via zero-width positive lookahead
(?!X) negativeLookAhead(RegexBuilder.()->Unit){} X, via zero-width negative lookahead
(?<=X) positiveLookBehind(RegexBuilder.()->Unit){} X, via zero-width positive lookbehind
(?<!X) negativeLookBehind(RegexBuilder.()->Unit){} X, via zero-width negative lookbehind
(?>X) independentNoneCapturingGroup(RegexBuilder.()->Unit){} X, as an independent, non-capturing group
You might also like...
Kotlin parser library with an easy-to-use DSL
Kotlin parser library with an easy-to-use DSL

Pratt Library for parsing expressions and a beautiful Kotlin DSL Just define your operators and operands with the Kotlin DSL and the parser is ready!

Kotlin DSL for Junit5

Kupiter is Kotlin DSL for Junit5. Current API is only for dynamic tests. Get it repositories { maven { url 'https://jitpack.io' } } dependencies

Kotlin-dsl-sample - Preferences project on android

kotlin-dsl-example Sample preferences project on android. How to use val

GitHub Actions Kotlin DSL

GitHub Actions Kotlin DSL Work in progress! The goal is to be able to describe GH Actions in Kotlin with all its perks, like: workflow( name = "Te

A simple, classic Kotlin MVI implementation based on coroutines with Android support, clean DSL and easy to understand logic

A simple, classic Kotlin MVI implementation based on coroutines with Android support, clean DSL and easy to understand logic

Kotlin DSL inspired by bhailang.js

Kotlin DSL inspired by bhailang.js

A light weight Compose Animation library to choreograph low level Animation API through Kotlin DSL.

Koreography Choreograph your Compose Animation 💃 🕺 A lightweight Compose Animation utility library to choreograph low-level Animation API (https://d

A small DSL to make building a conversation in Bukkit easy.

Konversation Konversation provides a simple builder to construct chains of prompts to be used in the conversation API present in Bukkit. Bukkit only p

Koin Annotations - help declare Koin definition in a very fast and intuitive way, and generate all underlying Koin DSL for you

The goal of Koin Annotations project is to help declare Koin definition in a very fast and intuitive way, and generate all underlying Koin DSL for you. The goal is to help developer experience to scale and go fast 🚀 , thanks to Kotlin Compilers.

Owner
Try to DDOS it 127.0.0.1
null
Android + Kotlin + Github Actions + ktlint + Detekt + Gradle Kotlin DSL + buildSrc = ❤️

kotlin-android-template ?? A simple Github template that lets you create an Android/Kotlin project and be up and running in a few seconds. This templa

Nicola Corti 1.5k Jan 3, 2023
A Kotlin DSL wrapper around the mikepenz/MaterialDrawer library.

MaterialDrawerKt Create navigation drawers in your Activities and Fragments without having to write any XML, in pure Kotlin code, with access to all t

Márton Braun 517 Nov 19, 2022
{ } Declarative Kotlin DSL for choreographing Android transitions

Transition X Kotlin DSL for choreographing Android Transitions TransitionManager makes it easy to animate simple changes to layout without needing to

Arunkumar 520 Dec 16, 2022
Kotlin Dsl for Android RecyclerView

KRecyclerDsl Kotlin Dsl for Android RecyclerView Exemple Sample project recyclerView.adapter = dataClassAdapter<MyView, MyDataClass>(R.layout.my_view,

Thomas Girard 14 Mar 31, 2019
The most complete and powerful data-binding library and persistence infra for Kotlin 1.3, Android & Splitties Views DSL, JavaFX & TornadoFX, JSON, JDBC & SQLite, SharedPreferences.

Lychee (ex. reactive-properties) Lychee is a library to rule all the data. ToC Approach to declaring data Properties Other data-binding libraries Prop

Mike 112 Dec 9, 2022
Nice and simple DSL for Espresso in Kotlin

Kakao Nice and simple DSL for Espresso in Kotlin Introduction At Agoda, we have more than 1000 automated tests to ensure our application's quality and

Agoda Company Pte Ltd. 1.1k Nov 22, 2022
DSL for constructing the drawables in Kotlin instead of in XML

Android Drawable Kotlin DSL DSL for constructing the drawables in Kotlin instead of in XML Examples Shape drawables <?xml version="1.0" encoding="utf-

Infotech Group 178 Dec 4, 2022
Lightweight Kotlin DSL dependency injection library

Warehouse DSL Warehouse is a lightweight Kotlin DSL dependency injection library this library has an extremely faster learning curve and more human fr

Osama Raddad 18 Jul 17, 2022
Code generation of Kotlin DSL for AWS CDK

Code generation of Kotlin DSL for AWS CDK

Semantic Configuration 5 Dec 24, 2022
Kotlin Object Notation - Lightweight DSL to build fluid JSON trees

Kotlin Object Notation Lightweight kotlin MPP DSL for building JSON trees Setup Just drop the dependency in your commonMain sourceSet kotlin { sourc

Martynas Petuška 43 Dec 10, 2022