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.

"(?<!\\\\)".freeze
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.

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

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

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

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

"(?<![A-z])".freeze
NO_TRAILING_ALPHABETICALS =
"(?![A-z])".freeze
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)".freeze

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