1Regexp::Stringify(3)  User Contributed Perl Documentation Regexp::Stringify(3)
2
3
4

NAME

6       Regexp::Stringify - Stringify a Regexp object
7

VERSION

9       This document describes version 0.06 of Regexp::Stringify (from Perl
10       distribution Regexp-Stringify), released on 2016-10-29.
11

SYNOPSIS

13       Assuming this runs on Perl 5.14 or newer.
14
15        use Regexp::Stringify qw(stringify_regexp);
16        $str = stringify_regexp(regexp=>qr/a/i);                       # '(^i:a)'
17        $str = stringify_regexp(regexp=>qr/a/i, with_qr=>1);           # 'qr(a)i'
18        $str = stringify_regexp(regexp=>qr/a/i, plver=>5.010);         # '(?:(?i-)a)'
19        $str = stringify_regexp(regexp=>qr/a/ui, plver=>5.010);        # '(?:(?i-)a)'
20

FUNCTIONS

22   stringify_regexp(%args) -> str
23       Stringify a Regexp object.
24
25       This routine is an alternative to Perl's default stringification of
26       Regexp object (i.e.:"$re") and has some features/options, e.g.:
27       producing regexp string that is compatible with certain perl versions.
28
29       If given a string (or other non-Regexp object), will return it as-is.
30
31       This function is not exported by default, but exportable.
32
33       Arguments ('*' denotes required arguments):
34
35       ·   plver => str
36
37           Target perl version.
38
39           Try to produce a regexp object compatible with a certain perl
40           version (should at least be >= 5.10).
41
42           For example, in perl 5.14 regex stringification changes, e.g.
43           "qr/hlagh/i" would previously be stringified as "(?i-xsm:hlagh)",
44           but now it's stringified as "(?^i:hlagh)". If you set "plver" to
45           5.10 or 5.12, then this routine will still produce the former. It
46           will also ignore regexp modifiers that are introduced in newer
47           perls.
48
49           Note that not all regexp objects are translatable to older perls,
50           e.g. if they contain constructs not known to older perls like
51           "(?^...)" before perl 5.14.
52
53       ·   regexp* => re
54
55       ·   with_qr => bool
56
57           If you set this to 1, then "qr/a/i" will be stringified as 'qr/a/i'
58           instead as '(?^i:a)'. The resulting string can then be eval-ed to
59           recreate the Regexp object.
60
61       Return value:  (str)
62

HOMEPAGE

64       Please visit the project's homepage at
65       <https://metacpan.org/release/Regexp-Stringify>.
66

SOURCE

68       Source repository is at
69       <https://github.com/perlancar/perl-Regexp-Stringify>.
70

BUGS

72       Please report any bugs or feature requests on the bugtracker website
73       <https://rt.cpan.org/Public/Dist/Display.html?Name=Regexp-Stringify>
74
75       When submitting a bug or request, please include a test-file or a patch
76       to an existing test-file that illustrates the bug or desired feature.
77

AUTHOR

79       perlancar <perlancar@cpan.org>
80
82       This software is copyright (c) 2016 by perlancar@cpan.org.
83
84       This is free software; you can redistribute it and/or modify it under
85       the same terms as the Perl 5 programming language system itself.
86
87
88
89perl v5.30.1                      2020-01-30              Regexp::Stringify(3)
Impressum