Skip to content

Commit

Permalink
Added Text::Patterns::HEX_WORD (issue #553).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Dec 14, 2024
1 parent 752dee5 commit b1ac537
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ronin/support/text/patterns/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ module Patterns
# @since 1.2.0
HEX_BYTE = /(?:0x)?[0-9a-fA-F]{2}/

# Regular expression for finding hexadecimal words (0000 - ffff).
#
# @since 1.2.0
HEX_WORD = /(?:0x)?[0-9a-fA-F]{4}/

# Regular expression for finding all hexadecimal numbers in text.
#
# @since 1.0.0
Expand Down
30 changes: 30 additions & 0 deletions spec/text/patterns/numeric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,36 @@
end
end

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

it "must match 0000 - ffff" do
expect("0000").to match(subject)
expect("ffff").to match(subject)
end

it "must match 0000 - FFFF" do
expect("0000").to match(subject)
expect("FFFF").to match(subject)
end

it "must match 0x0000 - 0xffff" do
expect("0x0000").to match(subject)
expect("0xffff").to match(subject)
end

it "must match 0x0000 - 0xFFFF" do
expect("0x0000").to match(subject)
expect("0xFFFF").to match(subject)
end

it "must only match four hexadecimal digits" do
string = "a1b2c3"

expect(string[subject]).to eq("a1b2")
end
end

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

Expand Down

0 comments on commit b1ac537

Please sign in to comment.