[#boost-urls-grammar-optional_rule] = xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/grammar.adoc[grammar]::optional_rule :relfileprefix: ../../../ :mrdocs: Match a rule, or the empty string == Synopsis Declared in `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/grammar/optional_rule.hpp#L84[boost/url/grammar/optional_rule.hpp]>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<xref:boost/urls/grammar/Rule.adoc[Rule] R> constexpr /* implementation-defined */ optional_rule(R const& r); ---- == Description Optional BNF elements are denoted with square brackets. If the specified rule returns any error it is treated as if the rule did not match. == 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::parse`]. [,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[] == 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_chars`], xref:boost/urls/grammar/parse-09.adoc[`parse`], xref:boost/urls/optional.adoc[`optional`], xref:boost/urls/grammar/token_rule.adoc[`token_rule`]. [.small]#Created with https://www.mrdocs.com[MrDocs]#