t-regx / T-Regx

Simple library for regular expressions in PHP.
https://t-regx.com
MIT License
448 stars 16 forks source link

Escapable masks #92

Closed danon closed 3 years ago

danon commented 3 years ago

Feature description

Add ability to create formatted patterns, but with ability to escape them.

With the snippet below, there's no possibility from the user perspective (the supplier of the mask/format string) to make e literal.

Pattern::format('welcome:e', [
  'e' => '\w+'
]);

We could created new method formatEscapable, which means any value in the format can be escaped.

Pattern::formatEscapable('welcome:e', '\\', [
  'e'  => '\w+',
  'e\e' => 'x', // disallowed
  'e\\' => 'x',  // disallowed
  '\\' => 'siema' // disallowed
]);

Question arises, what happens when someone passes quoted character that's not in the patterns, or leaves it as the last character in the mas

Pattern::formatEscapable('\e \x \', '\\', ['e'  => '\w+',]);

Wha should be the result? Replace \e but not \x and \? What if someone escaps the escape? Should the escape be the same? Disallowed? Or customizable?

danon commented 3 years ago

Descoped