Mark
05/04/2021, 3:10 AMRegex
that will never find/match any input string? Seems that each regex engine out there has a different best practice for making an ‘impossible’ regex.LeoColman
05/04/2021, 3:12 AMMark
05/04/2021, 3:13 AMMark
05/04/2021, 3:18 AM"""\b\B""".toRegex()
https://pl.kotl.in/743V8u8okephemient
05/04/2021, 4:20 AM"""\Z.""".toRegex()
(a.k.a. "$.".toRegex()
, as long as there isn't options = setOf(RegexOption.MULTILINE, RegexOption.DOT_MATCHES_ALL)
)ephemient
05/04/2021, 4:21 AM""".\A""".toRegex()
(or ".^".toRegex()
, provided there aren't those regex options)Mark
05/04/2021, 5:40 AM^\b$
as suggested here: https://stackoverflow.com/questions/1723182/a-regex-that-will-never-be-matched-by-anything/2302992#2302992Mark
05/04/2021, 5:42 AMMark
05/04/2021, 5:56 AM$.
and .^
are not efficient. So better to use ^.^
which is just 3 steps regardless of the length of input text. Testing using https://regex101.com/ephemient
05/04/2021, 5:56 AMm
off the modifiers listephemient
05/04/2021, 5:58 AMMark
05/04/2021, 6:03 AM^.^
to match anything regardless of the multiline flagephemient
05/04/2021, 6:04 AMMark
05/04/2021, 6:05 AM^.^
it seems to do what I want and is performantephemient
05/04/2021, 6:07 AMephemient
05/04/2021, 6:08 AM"(?!)".toRegex()
ephemient
05/04/2021, 6:09 AMMark
05/04/2021, 6:09 AM\A.\A
Mark
05/04/2021, 6:12 AMephemient
05/04/2021, 6:15 AM\Z.\A
, or just \Z.
or .\A
like I suggested at firstMark
05/04/2021, 6:22 AM.\A
is much slower https://pl.kotl.in/bHniyg34T
\Z.
is also much slower, but not nearly as slow as .\A
I can’t see any benefit of using \Z.\A
over \Z.
Vampire
05/04/2021, 7:52 AM[^\w\W]
which tries to match one character that is neither a word nor a non-word character.
You can probably speed it up by anchoring in the beginning like \A[^\w\W]
.
If you have possessive quantifiers you can probably also do .*+.
which should be quite efficient.Mark
05/04/2021, 8:55 AM\A[^\w\W]
is just two steps, so very efficient. https://regex101.com/r/AKtYle/1 https://pl.kotl.in/hdbNH73ItMark
05/04/2021, 9:03 AM\A.\A
is you don’t need to use @Suppress("RegExpUnexpectedAnchor")