Pattern: Literal bytes

“Literal bytes” is one of the patterns that you can select on the Match panel. Use this pattern to make a field match a specific piece of text exactly as you type it in.

This example shows how you can use the “literal bytes” pattern to make your regular expression match some text literally. You can find this example as “Pattern: literal bytes” in the RegexMagic library.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, click the New button to add a new sample and click the FFh button to switch the sample to hexadecimal mode. Then paste this block of bytes into the hex editor:
    00 10 2A 3B 4C 5D 6E 7F  8A FF 00 10 2A 7F 8A FF
  3. On the Match panel, set both “begin regex match at” and “end regex match at” to “anywhere”.
  4. Click the Add First Field button to add field 1.
  5. In the “pattern to match field” drop-down list, select “literal bytes”.



  6. Enter these bytes in the hexadecimal section:
    00 10 2A 3B 4C 5D 6E 7F  8A FF
  7. On the Regex panel, select “C# (.NET 2.0–4.8 & .NET Core 1.0–3.0)” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression. It is the sequence of bytes we entered with printable ASCII characters as literals (escaped if they are metacharacters) and all other bytes as hexadecimal escapes.
    \x00\x10\*;L\]n\x7F\x8A\xFF

    Required options: Case sensitive.
    Unused options: Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.

Related Examples

Reference