# \[ANN\] ReadableRegex.jl

**URL:** <https://discourse.julialang.org/t/ann-readableregex-jl/43450>\
**Category:** Package Announcements\
**Tags:** package, announcement\
**Created:** [July 21, 2020, 9:38pm UTC](https://discourse.julialang.org/t/ann-readableregex-jl/43450 "2020-07-21T21:38:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 21, 2020, 9:38pm UTC](https://discourse.julialang.org/t/ann-readableregex-jl/43450/1 "2020-07-21T21:38:22Z")

</div>

Hi everyone,

As it randomly came up on Slack today, I might as well announce a small new package here: ReadableRegex.jl [GitHub - jkrumbiegel/ReadableRegex.jl: regexes for people who don't really want to learn or read regexes](https://github.com/jkrumbiegel/ReadableRegex.jl)

The point of it is to be able to construct regular expressions in a verbose but easy to understand way, as the functions read almost like a natural sentence. This pays off over time as complex expressions stay easy to comprehend for people reading the source code. Normally, sufficiently complex regexes tend to be treated a bit like “magic” and nobody wants to touch them again if they seem to work.

Here’s an example from the readme. Can you quickly determine, what this regex does?

```julia
regex = r"[\+-]?(?:\d*\.)?\d+"

```

Now try this, without knowing the ReadableRegex syntax:

```julia
regex = maybe(["-", "+"]) * maybe(one_or_more(DIGIT) * ".") * at_least_one(DIGIT)

```

They do the same thing of course, which is matching different floating point numbers. Now imagine adding support for exponential syntax to the first one, for the second one it wouldn’t be that hard. It’s just difficult for humans to parse a sequential string representing nested expressions, obscured through abbreviations and lots of backslashes.

You can install it via ]add ReadableRegex. All docs are in the readme file.

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [July 21, 2020, 9:46pm UTC](https://discourse.julialang.org/t/ann-readableregex-jl/43450/2 "2020-07-21T21:46:35Z")

</div>

THANKS THANKS!

If there is one thing in my life I will NEVER understand, it is Regex. It is probably more complicated than quantum mechanics!!!  
Any time I had to do a regex match, I had to spend hours on stackoverflow, tutorials, and cryptic syntax, and trial and error to get it right.

This simplifies things tremendously!!!

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [July 21, 2020, 9:53pm UTC](https://discourse.julialang.org/t/ann-readableregex-jl/43450/3 "2020-07-21T21:53:58Z")

</div>

This looks nice! By the way, there is a similar package by @bramtayl, [https://github.com/bramtayl/RegularExpressions.jl](https://github.com/bramtayl/RegularExpressions.jl).

One thing that’s convenient about the macro is that the regex is compiled at macro expansion time, so you can use it in loops without loss of performance (whereas for a function-based approach, I think you would want to create the regex object before the loop and pass it in for maximal performance). I wonder if there’s a nice way to add that feature here.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 22, 2020, 3:43am UTC](https://discourse.julialang.org/t/ann-readableregex-jl/43450/4 "2020-07-22T03:43:20Z")

</div>

Ha interesting, the idea seems very similar but still the syntax is different. I do have a @compile macro included by the way, which allows to compile the whole function expression if the parts are known at compile time. It’s at the end of the readme

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [July 22, 2020, 3:45am UTC](https://discourse.julialang.org/t/ann-readableregex-jl/43450/5 "2020-07-22T03:45:17Z")

</div>

Man I need to remember this package next time I try to regex. I’m horrible at that stuff.

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [July 22, 2020, 10:28am UTC](https://discourse.julialang.org/t/ann-readableregex-jl/43450/6 "2020-07-22T10:28:36Z")

</div>

> [@jules](#):
>
> I do have a @compile macro included by the way, which allows to compile the whole function expression if the parts are known at compile time. It’s at the end of the readme

Ah cool! I had missed that.

---

<div class="post-metadata">

**Author:** ![bramtayl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bramtayl/32/3614_2.png) [@bramtayl](https://discourse.julialang.org/u/bramtayl)\
**Post date:** [July 23, 2020, 4:39pm UTC](https://discourse.julialang.org/t/ann-readableregex-jl/43450/7 "2020-07-23T16:39:30Z")

</div>

@jules I had similar goals when I wrote RegularExpressions.jl. Happy to collaborate if you want to combine efforts

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 25, 2020, 5:31am UTC](https://discourse.julialang.org/t/ann-readableregex-jl/43450/8 "2020-07-25T05:31:23Z")

</div>

Yes that would be nice, I haven’t used it that much in the wild, yet, so I don’t know which parts could be improved the most. I had a look at your package and it seems to offer a little bit more functionality that I could still add, like recursion and flags

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [July 25, 2020, 1:04pm UTC](https://discourse.julialang.org/t/ann-readableregex-jl/43450/9 "2020-07-25T13:04:31Z")

</div>

Who do you think you are? Some kind of superhero?

No but seriously, this is an awesome package idea. Thank you for the contribution
