Regexp...ringify(3pm)

πŸ“¦
version 0.06 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Regexp::Stringify β€” the little module that turns a Regexp object into a string, bestie. That's it, that's the whole vibe.


✨ VERSION ✨

This doc describes version 0.06 of Regexp::Stringify (she lives in the Perl distribution Regexp-Stringify), released on 2016-10-29. Yeah she's a lil vintage, she's iconic for it.


πŸ¦‹ SYNOPSIS πŸ¦‹

So picture this: you're on Perl 5.14 or newer. Immaculate. Then:

use Regexp::Stringify qw(stringify_regexp);
$str = stringify_regexp(regexp=>qr/a/i);                       # '(^i:a)'
$str = stringify_regexp(regexp=>qr/a/i, with_qr=>1);           # 'qr(a)i'
$str = stringify_regexp(regexp=>qr/a/i, plver=>5.010);         # '(?:(?i-)a)'
$str = stringify_regexp(regexp=>qr/a/ui, plver=>5.010);        # '(?:(?i-)a)'

Look at those outputs. Obsessed. πŸ’…


πŸŽ€ FUNCTIONS πŸŽ€

🌸 stringify_regexp(%args) -> str

Stringify a Regexp object. That's the whole job and she does it flawlessly, no notes.

This routine is the alternative to Perl's default stringification of a Regexp object (you know, the classic "$re"), except she comes with extra features and options, like: producing a regexp string that plays nice with specific perl versions. Highkey the upgrade.

Here's the sweet part β€” if you hand her a string (or literally any other non-Regexp object), she just hands it right back to you as-is. No drama, no fuss. 🫢

She is not exported by default, but she is exportable. So go get her.

Arguments β€” and the * means "required, bestie, you literally cannot skip this one":

  • plver => str β€” Target perl version.

She'll try to produce a regexp object that's compatible with a certain perl version (and it should at least be >= 5.10, mkay).

For example: in perl 5.14 the regex stringification changed, so "qr/hlagh/i" used to stringify as "(?i-xsm:hlagh)", but now it stringifies as "(?^i:hlagh)". The way that if you set plver to 5.10 or 5.12, this routine will still produce the former one for you. And she'll also ignore regexp modifiers that got introduced in newer perls. Time travel but make it regex. ⏳

Heads up though β€” not every regexp object can be translated back to older perls 😭 Like if they contain constructs that older perls simply don't know about, e.g. "(?^...)" before perl 5.14. She's good, she's not a miracle worker.
  • regexp* => re β€” the required one, the main character of the argument list. πŸ‘‘
  • with_qr => bool β€” Set this to 1 and "qr/a/i" gets stringified as 'qr/a/i' instead of as '(?^i:a)'. Then you can eval that resulting string to recreate the Regexp object. Chef's kiss, round-trip slay. πŸ”₯

Return value: (str) β€” yeah girl, you get a string back.


🧚 HOMEPAGE 🧚

Go visit the project's homepage at <https://metacpan.org/release/Regexp-Stringify>. It's giving home. It's giving comfort. 🏑


🌈 SOURCE 🌈

The source repository is at <https://github.com/perlancar/perl-Regexp-Stringify>. Go peek, go lurk, it's fine, we all do it. πŸ‘€


πŸ’€ BUGS πŸ’€

Found a bug? Got a feature request? Report it on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=Regexp-Stringify>. She wants to hear from you fr fr.

And when you do submit a bug or a request, please include a test-file β€” or a patch to an existing test-file β€” that illustrates the bug or the desired feature. Don't just show up with vibes, show up with a test file. The maintainers will love you for it. πŸ™ˆ


πŸ‘‘ AUTHOR πŸ‘‘

perlancar <perlancar@cpan.org> β€” the legend, the moment, the whole entire icon.


This software is copyright (c) 2016 by perlancar@cpan.org.

It's free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. So go forth and remix, just keep it the same terms, periodt. ✨


And that's the whole page, bestie! This was Regexp...ringify(3pm) from perl v5.36.0, dated 2022-10-13 β€” thanks for sticking around till the footer, you're the real one. Bye, ily, go stringify some regexps πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from