Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
regex_match(3)		      rationL User Manual		regex_match(3)

NAME
       regex_match  -  Matche a	string from against a compiled regular expres-
       sion

SYNOPSIS
	      #include <rationl.h>

	      int regex_match(reg_t re,	char *string);

DESCRIPTION
       regex_match() matches a regular expression against a string and returns
       true(1) if the regular expression matches the string or false(0)	other-
       wise.

       re The regular expression that was compiled using regex_compile

       string The string to match the regular expression against

RETURN VALUE
       regex_match() returns true(1) if	the  string  passed  as	 parameter  is
       matched by the regular expression false(0) if not.

EXAMPLES
       Program that matches an email address passed as first parameter

	      #include <rationl.h>
	      #include <err.h>
	      #include <stdio.h>

	      int main(int argc, char**	argv)
	      {
		  if(argc != 2)
		      errx(1, "No input	email address found.");

		  reg_t	re = regex_compile("\\w+(\\.\\w+)?@\\w+(\\.[a-z]{2,})+");

		  if(regex_match(re, argv[1]))
		      printf("%s is a valid email.\n", argv[1]);
		  else
		      printf("%s is not	a valid	email.\n", argv[1]);
		  regex_free(re);
		  return 0;
	      }

rationL	0.1.0			 April 5, 2021			regex_match(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=regex_match&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help