[#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#L83[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 */::xref:boost/urls/grammar/implementation_defined/optional_rule_t.adoc[optional_rule_t]<R> 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-02.adoc[grammar::parse]. [,cpp] ---- system::result< optional< core::string_view > > rv = parse( "", optional_rule( token_rule( alpha_chars ) ) ); ---- === BNF [,cpp] ---- optional = [ rule ] ---- === Specification * link:https://datatracker.ietf.org/doc/html/rfc5234#section-3.8[3.8. Optional Sequence (rfc5234)] == Parameters |=== | Name | Description | *r* | The rule to match |=== == See Also xref:boost/urls/grammar/alpha_chars.adoc[alpha_chars], xref:boost/urls/grammar/parse-02.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]#