# perldoc > DateTime::Format::Builder::Parser::Regex

---
type: CommandReference
command: DateTime::Format::Builder::Parser::Regex
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `regex => qr/.../` — required regex to capture date parts
- `params => [...]` — required arrayref of key names mapped to regex captures
- `extra => {...}` — optional hashref of extra arguments to `DateTime->new`
- `constructor => [...]` — optional custom constructor (arrayref or coderef)

## Name

Regex based date parsing

## Synopsis

perl
my $parser = DateTime::Format::Builder->create_parser(
    regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)$/,
    params => [qw( year month day hour minute second )],
);
## Options

In addition to the common keys from `DateTime::Format::Builder`, the `Regex` parser supports:

- `regex` — a regular expression that captures elements of the datetime string. Required.
- `params` — an arrayref of key names. Captures from the regex are mapped to these (`$1` to the first element, `$2` to the second, etc.) and passed to `DateTime->new`. Required.
- `extra` — a hashref of extra arguments to `DateTime->new`. For example, you can set default year or time zone:

    ```perl
    extra => { year => 2004, time_zone => "Australia/Sydney" }
    
- `constructor` — either an arrayref or a coderef. If an arrayref, the first element is a class name or object, and the second is a method name (or coderef). Arguments are anything in `$p` and `extra`. If a coderef, it is called with `$self`, `$p`, and `extra`. The method is expected to return a valid `DateTime` object or `undef` on failure.

    ```perl
    $self->$coderef( %{$p}, %{ $self->{extra} } );
    
## Examples

perl
my $parser = DateTime::Format::Builder->create_parser(
    regex  => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)$/,
    params => [qw( year month day hour minute second )],
);
## See Also

- [DateTime::Format::Builder](https://www.chedong.com/phpMan.php/perldoc/DateTime%3A%3AFormat%3A%3ABuilder/markdown)
- [DateTime](https://www.chedong.com/phpMan.php/perldoc/DateTime/markdown)
- perl
- [datetime@perl.org](mailto:datetime@perl.org) mailing list
- [http://datetime.perl.org/](http://datetime.perl.org/)