Module: Rubymisc::Regex::Manual

Defined in:
lib/rubymisc/regex/manual.rb

Class Method Summary collapse

Class Method Details

.manObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rubymisc/regex/manual.rb', line 6

def man
  <<-EOS
Ruby character representations
------------------------------
  Sequence        Meaning
  \\a              Alert (bell), \\x07.
  \\b              Backspace, \\x08, supported only in character class.
  \\e              ESC character, \\x1B.
  \\n              Newline, \\x0A.
  \\r              Carriage return, \\x0D.
  \\f              Form feed, \\x0C.
  \\t              Horizontal tab \\x09.
  \\v              Vertical tab, \\x0B.
  \\0octal         Character specified by a two-digit octal code.
  \\xhex           Character specified by a two-digit hexadecimal code.
  \\cchar          Named control character.

Ruby character classses and class-like constructs
-------------------------------------------------
  Class           Meaning
  [...]           A single character listed, or contained within a listed range.
  [^...]          A single character not listed, and not contained within a listed range.
  .               Any character, except a line terminator (unless single-line mode, s).
  \\w              Word character.
  \\W              Nonword character.
  \\d              Digit.
  \\D              Nondigit.
  \\s              Whitespace character, [\\f\\n\\r\\t\\v].
  \\S              Nonwhitespace character, [^\\f\\n\\r\\t\\v].
  \\h              Hexadecimal digit.
  \\H              Negated form of \\h.

Ruby anchors and other zero-width tests
---------------------------------------
  Sequence        Meaning
  ^               Start of string, or the point after any newline.
  \\A              Beginning of string, in all match modes.
  $               End of string, or the point before any newline.
  \\Z              End of string, but before any final line terminator, in all match modes.
  \\z              End of string, in all match modes.
  \\b              Boundary between a \\w character and a \W character.
  \\B              Not-word-boundary.
  \\G              End of the previous match.
  (?=...)         Positive lookahead.
  (?!...)         Negative lookahead.

Ruby comments and mode modifiers
--------------------------------
  Mode character  Meaning
  m               Dot(.) matches any character, including a line terminator.
            Note that this is different from most regex implementations.
  x               Ignore whitespace, and allow embedded comment starting with #.
  i               Case-insensitive match.
  n               Turn off wide-character processing.
  o               Evaluate \#{...} substitutions only once. Default is to evaluate each time the regex is evaluated.
  (?imns-imns)    Turn match flags on or off for the rest of pattern.
  (?imns-imns:    Turn match flags on or off for the rest of the subexpression.
  ...)
  (?#...)         Treat substring as a comment.
  #...            Treat rest of line as a comment in /x mode.
  (?<=...)        Positive lookbehind.
  (?<!...)        Negative lookbehind.

Ruby grouping, capturing, conditional and control
-------------------------------------------------
  Sequence        Meaning
  (...)           Grouping. Submatches fill \\1, \\2, ... and $1, $2, ...
  (?<name>...)    Named captured. Grouped match will fill \\k<name>.
  \\n              In a regular expression, match what was matched by the nth earlier submatch.
  $n              In a replacement string, contains the nth earlier submatch.
  \\k<name>        In a replacement string, contains the named submatch name.
  (?:...)         Grouping-only parentheses, no capturing.
  (?>...)         Atomic grouping.
  ...|...         Alternation; match one or the other.
  *               Match 0 or more times.
  +               Match 1 or more times.
  ?               Match 1 or 0 times.
  {n}             Match exactly n times.
  {n,}            Match at least n times.
  {,n}            Match at most n times.
  {x,y}           Match at least x times, but no more than y times.
  *?              Match 0 or more times, but as few times as possible.
  +?              Match 1 or more times, but as few times as possible.
  ??              Match 0 or 1 times, but as few times as possible.
  {n,}?           Match at least n times, but as few times as possible.
  {x,y}?          Match at least x times, no more than y times, and as few times as possible.

Ruby replacement sequences
--------------------------
  Sequence        Meaning
  $1, $2, ...     Captured submatches.
  ${name}         Matched text of a named capture group.
  $'              Text before match.
  $&              Text of match.
  $`              Text after match.
  $+              Last parenthesized match.
  $~              Match data. Encapsulates the results of a successful pattern match.
  EOS
end