Skip to content

Commit

Permalink
Added Text::Patterns::DECIMAL_BYTE (issue #553).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Dec 12, 2024
1 parent e16232d commit ab071a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/ronin/support/text/patterns/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ module Patterns
# @since 1.0.0
NUMBER = /[0-9]+/

# Regular expression for finding a decimal bytes (0 - 255)
#
# @since 1.2.0
DECIMAL_BYTE = /(?<=[^\d]|^)(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])(?=[^\d]|$)/

# Regular expression for finding a decimal octet (0 - 255)
#
# @since 0.4.0
DECIMAL_OCTET = /(?<=[^\d]|^)(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])(?=[^\d]|$)/
DECIMAL_OCTET = DECIMAL_BYTE

# Regular expression for finding all hexadecimal numbers in text.
#
Expand Down
12 changes: 10 additions & 2 deletions spec/text/patterns/numeric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
end
end

describe "DECIMAL_OCTET" do
subject { described_class::DECIMAL_OCTET }
describe "DECIMAL_BYTE" do
subject { described_class::DECIMAL_BYTE }

it "must match 0 - 255" do
numbers = (0..255).map(&:to_s)
Expand All @@ -27,6 +27,14 @@
end
end

describe "DECIMAL_OCTET" do
subject { described_class::DECIMAL_OCTET }

it "must be an alias for DECIMAL_BYTE" do
expect(subject).to be(described_class::DECIMAL_BYTE)
end
end

describe "HEX_NUMBER" do
subject { described_class::HEX_NUMBER }

Expand Down

0 comments on commit ab071a5

Please sign in to comment.