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.
- Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
- 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
- On the Match panel, set both “begin regex match at” and “end regex match at” to “anywhere”.
- Click the button to add field .
- In the “pattern to match field” drop-down list, select “literal bytes”.
- Enter these bytes in the hexadecimal section:
00 10 2A 3B 4C 5D 6E 7F 8A FF
- On the Regex panel, select “C# (.NET 2.0–7.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.
Required options: Case sensitive.
Unused options: Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.