diff --git a/lib/ronin/support/text/patterns/numeric.rb b/lib/ronin/support/text/patterns/numeric.rb index c60fceb1..d558c85a 100644 --- a/lib/ronin/support/text/patterns/numeric.rb +++ b/lib/ronin/support/text/patterns/numeric.rb @@ -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 diff --git a/spec/text/patterns/numeric_spec.rb b/spec/text/patterns/numeric_spec.rb index e0e25bdc..79a4d361 100644 --- a/spec/text/patterns/numeric_spec.rb +++ b/spec/text/patterns/numeric_spec.rb @@ -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 }