Class: Friends::RegexBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/friends/regex_builder.rb

Constant Summary collapse

NO_LEADING_BACKSLASH =

We don’t want to match strings that are “escaped” with a leading backslash.

"(?<!\\\\)"
NO_LEADING_ASTERISKS =

We don’t want to match strings that are directly touching double asterisks as these are treated as sacred by our program.

"(?<!\\*\\*)"
NO_TRAILING_ASTERISKS =
"(?!\\*\\*)"
NO_LEADING_UNDERSCORES =

We don’t want to match strings that are directly touching underscores as these are treated as sacred by our program.

"(?<!_)"
NO_TRAILING_UNDERSCORES =
"(?!_)"
NO_LEADING_ALPHABETICALS =

We don’t want to match strings that are part of other words.

"(?<![A-z])"
NO_TRAILING_ALPHABETICALS =
"(?![A-z])"
IGNORE_CASE =

We ignore case within the regex as opposed to globally to allow consumers of this API the ability to pass in strings that turn off this modifier with the “(?-i)” string.

"(?i)"

Class Method Summary collapse

Class Method Details

.regex(str) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/friends/regex_builder.rb', line 30

def self.regex(str)
  Regexp.new(
    NO_LEADING_BACKSLASH +
    NO_LEADING_ASTERISKS +
    NO_LEADING_UNDERSCORES +
    NO_LEADING_ALPHABETICALS +
    IGNORE_CASE +
    str +
    NO_TRAILING_ALPHABETICALS +
    NO_TRAILING_UNDERSCORES +
    NO_TRAILING_ASTERISKS
  )
end