[#boost-urls-grammar-range_rule-06]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/grammar.adoc[grammar]::range&lowbar;rule
:relfileprefix: ../../../
:mrdocs:


Match a repeating number of elements

== Synopsis


Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/grammar/range_rule.hpp#L509[boost&sol;url&sol;grammar&sol;range&lowbar;rule&period;hpp]&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    xref:boost/urls/grammar/Rule.adoc[Rule] R1,
    xref:boost/urls/grammar/Rule.adoc[Rule] R2&gt;
constexpr
&sol;&ast; implementation-defined &ast;&sol;::xref:boost/urls/grammar/implementation_defined/range_rule_t.adoc[range&lowbar;rule&lowbar;t]&lt;R1, R2&gt;
range&lowbar;rule(
    R1 const& first,
    R2 const& next,
    std::size&lowbar;t N = 0,
    std::size&lowbar;t M = std&colon;&colon;size&lowbar;t(&hyphen;1)) noexcept;
----

== Description


Two rules are used for match&period; The rule    `first` is used for matching the first    element, while the `next` rule is used    to match every subsequent element&period;        Normally when the rule returns an error,    the range ends and the input is rewound to    one past the last character that matched    successfully&period; However, if the rule returns    the special value xref:boost/urls/grammar/error.adoc[error&colon;&colon;end&lowbar;of&lowbar;range], the    input is not rewound&period; This allows for rules    which consume input without producing    elements in the range&period; For example, to    relax the grammar for a comma&hyphen;delimited    list by allowing extra commas in between    elements&period;


=== Value Type

[,cpp]
----
using value_type = range< typename Rule::value_type >;
----

=== Example

Rules are used with the function xref:boost/urls/grammar/parse-02.adoc[parse]&period;

[,cpp]
----
// range    = [ token ] *( "," token )

system::result< range< core::string_view > > rv = parse( "whiskey,tango,foxtrot",
    range_rule(
        token_rule( alpha_chars ),          // first
        tuple_rule(                      // next
            squelch( delim_rule(',') ),
            token_rule( alpha_chars ) ) ) );
----

=== BNF

[,cpp]
----
range       = <1>*<1>first
            / first <N-1>*<M-1>next
----

=== Specification

* link:https://datatracker.ietf.org/doc/html/rfc5234#section-3.6[3&period;6&period;  Variable Repetition (rfc5234)]



== Parameters


|===
| Name | Description

| *first*
| The rule to use for matching    the first element&period; If this rule returns    an error, the range is empty&period;


| *next*
| The rule to use for matching    each subsequent element&period; The range extends    until this rule returns an error&period;


| *N*
| The minimum number of elements for    the range to be valid&period; If omitted, this    defaults to zero&period;


| *M*
| The maximum number of elements for    the range to be valid&period; If omitted, this    defaults to unlimited&period;


|===

== See Also


xref:boost/urls/grammar/alpha_chars.adoc[alpha&lowbar;chars],        xref:boost/urls/grammar/delim_rule-01.adoc[delim&lowbar;rule],        xref:boost/urls/grammar/error.adoc[error&colon;&colon;end&lowbar;of&lowbar;range],        xref:boost/urls/grammar/parse-02.adoc[parse],        xref:boost/urls/grammar/range.adoc[range],        xref:boost/urls/grammar/tuple_rule.adoc[tuple&lowbar;rule],        xref:boost/urls/grammar/squelch.adoc[squelch]&period;






[.small]#Created with https://www.mrdocs.com[MrDocs]#
