Module: RegexpExamples
- Defined in:
- lib/regexp-examples/groups.rb,
lib/regexp-examples/parser.rb,
lib/regexp-examples/helpers.rb,
lib/regexp-examples/version.rb,
lib/regexp-examples/constants.rb,
lib/regexp-examples/repeaters.rb,
lib/regexp-examples/backreferences.rb,
lib/regexp-examples/chargroup_parser.rb,
lib/regexp-examples/unicode_char_ranges.rb
Defined Under Namespace
Modules: ForceLazyEnumerators, GroupWithIgnoreCase, RandomResultBySample
Classes: BackReferenceGroup, BackReferenceReplacer, BaseRepeater, CharGroup, ChargroupParser, DotGroup, GroupResult, MultiGroup, OneTimeRepeater, OrGroup, Parser, PlaceHolderGroup, PlusRepeater, QuestionMarkRepeater, RangeRepeater, ResultCountLimiters, SingleCharGroup, StarRepeater, UnicodeCharRanges
Constant Summary
collapse
- IllegalSyntaxError =
Class.new(StandardError)
- VERSION =
'1.1.3'
- BackslashCharMap =
Map of special regex characters, to their associated character sets
{
'd' => CharSets::Digit,
'D' => CharSets::Any - CharSets::Digit,
'w' => CharSets::Word,
'W' => CharSets::Any - CharSets::Word,
's' => CharSets::Whitespace,
'S' => CharSets::Any - CharSets::Whitespace,
'h' => CharSets::Hex,
'H' => CharSets::Any - CharSets::Hex,
't' => ["\t"], 'n' => ["\n"], 'r' => ["\r"], 'f' => ["\f"], 'a' => ["\a"], 'v' => ["\v"], 'e' => ["\e"], }.freeze
- POSIXCharMap =
{
'alnum' => CharSets::Upper | CharSets::Lower | CharSets::Digit,
'alpha' => CharSets::Upper | CharSets::Lower,
'blank' => [' ', "\t"],
'cntrl' => CharSets::Control,
'digit' => CharSets::Digit,
'graph' => (CharSets::Any - CharSets::Control) - [' '], 'lower' => CharSets::Lower,
'print' => CharSets::Any - CharSets::Control,
'punct' => CharSets::Punct,
'space' => CharSets::Whitespace,
'upper' => CharSets::Upper,
'xdigit' => CharSets::Hex,
'word' => CharSets::Word,
'ascii' => CharSets::Any
}.freeze
- NamedPropertyCharMap =
UnicodeCharRanges.new
Class Method Summary
collapse
Class Method Details
.join_preserving_capture_groups(result) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/regexp-examples/helpers.rb', line 16
def self.join_preserving_capture_groups(result)
result.flatten!
subgroups = result
.map(&:all_subgroups)
.flatten
subgroups.delete_if do |subgroup|
subgroups.count { |other_subgroup| other_subgroup.group_id == subgroup.group_id } > 1
end
GroupResult.new(result.join, nil, subgroups)
end
|
.map_random_result(repeaters) ⇒ Object
33
34
35
|
# File 'lib/regexp-examples/helpers.rb', line 33
def self.map_random_result(repeaters)
generic_map_result(repeaters, :random_result)
end
|
.map_results(repeaters) ⇒ Object
29
30
31
|
# File 'lib/regexp-examples/helpers.rb', line 29
def self.map_results(repeaters)
generic_map_result(repeaters, :result)
end
|
.MaxGroupResults ⇒ Object
.MaxRepeaterVariance ⇒ Object
.permutations_of_strings(arrays_of_strings) ⇒ Object
Given an array of arrays of strings, returns all possible perutations for strings, created by joining one element from each array
For example: permutations_of_strings [ [‘a’], [‘b’], [‘c’, ‘d’, ‘e’] ] #=> [‘abc’, ‘abd’, ‘abe’] permutations_of_strings [ [‘a’, ‘b’], [‘c’, ‘d’] ] #=> [ ‘ac’, ‘ad’, ‘bc’, ‘bd’ ]
8
9
10
11
12
13
14
|
# File 'lib/regexp-examples/helpers.rb', line 8
def self.permutations_of_strings(arrays_of_strings)
first = arrays_of_strings.shift
return first if arrays_of_strings.empty?
first.product(permutations_of_strings(arrays_of_strings)).map do |result|
join_preserving_capture_groups(result)
end
end
|