1GraphViz::Regex(3) User Contributed Perl Documentation GraphViz::Regex(3)
2
3
4
6 GraphViz::Regex - Visualise a regular expression
7
9 use GraphViz::Regex;
10
11 my $regex = '(([abcd0-9])|(foo))';
12
13 my $graph = GraphViz::Regex->new($regex);
14 print $graph->as_png;
15
17 This module attempts to visualise a Perl regular expression.
18 Understanding regular expressions is tricky at the best of times, and
19 regexess almost always evolve in ways unforseen at the start. This
20 module aims to visualise a regex as a graph in order to make the
21 structure clear and aid in understanding the regex.
22
23 The graph visualises how the Perl regular expression engine attempts to
24 match the regex. Simple text matches or character classes are
25 represented by.box-shaped nodes. Alternations are represented by a
26 diamond-shaped node which points to the alternations. Repetitions are
27 represented by self-edges with a label of the repetition type (the
28 nodes being repeated are pointed to be a full edge, a dotted edge
29 points to what to match after the repetition). Matched patterns (such
30 as $1, $2, etc.) are represented by a 'START $1' .. 'END $1' node pair.
31
32 This uses the GraphViz module to draw the graph.
33
35 new
36 This is the constructor. It takes one mandatory argument, which is a
37 string of the regular expression to be visualised. A GraphViz object is
38 returned.
39
40 my $graph = GraphViz::Regex->new($regex);
41
42 as_*
43 The regex can be visualised in a number of different graphical formats.
44 Methods include as_ps, as_hpgl, as_pcl, as_mif, as_pic, as_gd, as_gd2,
45 as_gif, as_jpeg, as_png, as_wbmp, as_ismap, as_imap, as_vrml, as_vtx,
46 as_mp, as_fig, as_svg. See the GraphViz documentation for more
47 information. The two most common methods are:
48
49 # Print out a PNG-format file
50 print $g->as_png;
51
52 # Print out a PostScript-format file
53 print $g->as_ps;
54
56 Note that this module relies on debugging information provided by Perl,
57 and is known to fail on at least two versions of Perl: 5.005_03 and
58 5.7.1. Sorry about that - please use a more recent version of Perl if
59 you want to use this module.
60
62 Leon Brocard <acme@astray.com>
63
65 Copyright (C) 2000-1, Leon Brocard
66
67 This module is free software; you can redistribute it or modify it
68 under the Perl License, a copy of which is available at
69 <http://dev.perl.org/licenses/>.
70
71
72
73perl v5.32.0 2020-07-28 GraphViz::Regex(3)