EliziumNet / RexFs

Regular expression based Bulk File/Directory renamer
MIT License
4 stars 2 forks source link

Add @ccelerators to aid user to specify commonly used regexes #11

Open plastikfan opened 3 years ago

plastikfan commented 3 years ago

For example, date regexes could be a common used pattern but can become onerous to keep having to specify them. Come up with a way that these can be accelerated.

We should use a character that does not have a special meaning in regex, so @ would be a good contender.

To capture a date, the user would need to specify the following pattern:

-Pattern '(?\d{4})-(?\d{2})-(?\d{2})'

This could be accelerated to something like

-Pattern '@/ymd/'

So when creating a regex via New-RegularExpression, an initial parse has to be performed to see if it contains any accelerators and then replace them with the appropriate regex pattern.

The catalogue concept can be extended to include transformers, but that would be for a separate issue.

This should be implemented as a plugin, so it requires #23 to be implemented first.

plastikfan commented 3 years ago

Date accelerators:

assumption, each date consituent can be separated with:

a date may be wrapped in any bracket type

use the date formats as defined in .net: Custom date and time format strings, note that not all of these date formats need to be supported, but if we stick to this standard, it will be much easier for comprehension and there is already a spec we can work to. Note this only refers to the ouput; ie the With/Paste formatters

if we have @/dmy/ in the source (Pattern), then we can reference in the output (With/Paste) either using explicit named group references, or we can perform a reformatting using @/.net format string/. So the presence of a date accelerator in the source, means we reformat in the output as @/d-format/

Using this scheme, each formatter in the ouput knows where to gets its input, so for example 'ddd' represents 'The abbreviated name of the day of the week.'; this means that it will use ${d} as captured in the named group ref and map this to the day of the week.

We can also have an accelerator, that consumes the rest of the input source and stores in special variable r_.