Loading...
Searching...
No Matches
seqan3::regex_validator Class Reference
Argument Parser

A validator that checks if a matches a regular expression pattern. More...

`#include <seqan3/argument_parser/validators.hpp>`

Inheritance diagram for seqan3::regex_validator:
[legend]

## Public Types

using | option_value_type = std::string
| Type of values that are tested by validator.

## Public Member Functions

std::string | get_help_page_message () const
| Returns a message that can be appended to the (positional) options help page info.
void | operator() (option_value_type const &cmp) const
| Tests whether cmp lies inside values.
template<std::ranges::forward_range range_type> requires std::convertible_to<std::ranges::range_reference_t<range_type>, option_value_type const &>
void | operator() (range_type const &v) const
| Tests whether every filename in list v matches the pattern.
| regex_validator (std::string const &pattern_)
| Constructing from a vector.

## Additional Inherited Members

Related Symbols inherited from validator
using | option_value_type
| The type of value on which the validator is called on.
void | operator() (option_value_type const &cmp) const
| Validates the value 'cmp' and throws a seqan3::validation_error on failure.

## Detailed Description

A validator that checks if a matches a regular expression pattern.

On construction, the validator must receive a pattern for a regular expression. The pattern variable will be used for constructing a std::regex and the validator will call std::regex_match on the command line argument. Note: A regex_match will only return true if the strings matches the pattern completely (in contrast to regex_search which also matches substrings).

The class than acts as a functor, that throws a seqan3::validation_error exception whenever string does not match the pattern.

// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
#include <seqan3/argument_parser/all.hpp>
#include <seqan3/core/debug_stream.hpp>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
std::string my_string;
seqan3::regex_validator my_validator{"[a-zA-Z]+@[a-zA-Z]+\\.com"};
myparser.add_option(my_string, 's', "str", "Give me a string.", seqan3::option_spec::standard, my_validator);
// an exception will be thrown if the user specifies a string
// that is no email address ending on .com
try
{
myparser.parse();
}
catch (seqan3::argument_parser_error const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
seqan3::debug_stream << "email address given by user passed validation: " << my_string << "\n";
return 0;
}
all.hpp
Meta-header for the Argument Parser module .
std::string
std::cerr
seqan3::argument_parser_error
Argument parser exception that is thrown whenever there is an error while parsing the command line ar...
Definition exceptions.hpp:39
seqan3::argument_parser
The SeqAn command line parser.
Definition argument_parser.hpp:147
seqan3::argument_parser::add_option
void add_option(option_type &value, char const short_id, std::string const &long_id, std::string const &desc, option_spec const spec=option_spec::standard, validator_type option_validator=validator_type{})
Adds an option to the seqan3::argument_parser.
Definition argument_parser.hpp:238
seqan3::argument_parser::parse
void parse()
Initiates the actual command line parsing.
Definition argument_parser.hpp:404
seqan3::regex_validator
A validator that checks if a matches a regular expression pattern.
Definition validators.hpp:931
debug_stream.hpp
Provides seqan3::debug_stream and related types.
seqan3::standard
@ standard
The default were no checking or special displaying is happening.
Definition auxiliary.hpp:250
seqan3::debug_stream
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:38
std::runtime_error::what
T what(T... args)

Remarks
  For a complete overview, take a look at Argument Parser

## Constructor & Destructor Documentation

## regex_validator()

seqan3::regex_validator::regex_validator | ( | std::string const & | pattern_ | ) |

inline

Constructing from a vector.

Parameters

  [in] | pattern_ | The pattern to match.

## Member Function Documentation

## get_help_page_message()

std::string seqan3::regex_validator::get_help_page_message | ( |  | ) | const

inline

Returns a message that can be appended to the (positional) options help page info.

Implements validator.

## operator()() [1/2]

void seqan3::regex_validator::operator() | ( | option_value_type const & | cmp | ) | const

inline

Tests whether cmp lies inside values.

Parameters

  [in] | cmp | The value to validate.

Exceptions

  seqan3::validation_error |

## operator()() [2/2]

template<std::ranges::forward_range range_type>
requires std::convertible_to<std::ranges::range_reference_t<range_type>, option_value_type const &>

void seqan3::regex_validator::operator() | ( | range_type const & | v | ) | const

inline

Tests whether every filename in list v matches the pattern.

Template Parameters

  range_type | The type of range to check; must model std::ranges::forward_range and the value type must be convertible to std::string.

Parameters

  v | The input range to iterate over and check every element.

Exceptions

  seqan3::validation_error |

The documentation for this class was generated from the following file:

- validators.hpp

Hide me