[#boost-urls-grammar-optional_rule]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/grammar.adoc[grammar]::optional&lowbar;rule
:relfileprefix: ../../../
:mrdocs:

Match a rule, or the empty string

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;xref:boost/urls/grammar/Rule.adoc[Rule] R&gt;
constexpr
&sol;&ast; implementation-defined &ast;&sol;
optional&lowbar;rule(R const& r);
----

== Description

Optional BNF elements are denoted with square brackets&period; If the specified rule returns any error it is treated as if the rule did not match&period;

== Value Type

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

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

[,cpp]
----
system::result< optional< core::string_view > > rv = parse( "", optional_rule( token_rule( alpha_chars ) ) );
----
== BNF

[,cpp]
----
optional     = [ rule ]
----
== Specification

* https://datatracker.ietf.org/doc/html/rfc5234#section-3.8[3&period;8&period;  Optional Sequence (rfc5234)]

== Return Value

The adapted rule

== Parameters

[cols=2]
|===
| Name
| Description
| *r*
| The rule to match
|===

== See Also

xref:boost/urls/grammar/alpha_chars.adoc[`alpha&lowbar;chars`], xref:boost/urls/grammar/parse-09.adoc[`parse`], xref:boost/urls/optional.adoc[`optional`], xref:boost/urls/grammar/token_rule.adoc[`token&lowbar;rule`]&period;


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