[UP]


Manual Reference Pages  - regerror (3)

NAME

regerror(3f) - [M_regex] maps a non-zero errcode from either regcomp(3f) or regexec(3f) to a human-readable, printable message.

CONTENTS

Synopsis
Description
Options
Example

SYNOPSIS

function regerror(this,errcode) result(errmsg)

type(regex_type), intent(in) :: this integer, intent(in) :: errcode character(len=:),allocatable :: errmsg

DESCRIPTION

The REGCOMP() function compiles an RE written as a string into an internal form, REGEXEC() matches that internal form against a string and reports results, REGERROR() transforms error codes from either into human-readable messages, and REGFREE() frees any dynamically-allocated storage used by the internal form of an RE.

These routines implement IEEE Std 1003.2 (POSIX.2) regular expressions (RE s); see re_format(7).

Specifically, The REGERROR(3f) function maps a non-zero errcode from either REGCOMP(3f) or REGEXEC(3f) to a human-readable, printable message. If THIS is non-NULL, the error code should have arisen from use of the regex_t pointed to by THIS, and if the error code came from REGCOMP(), it should have been the result from the most recent REGCOMP() using that regex_t.

Non-zero error codes from regcomp() and regexec() include the following:
REG_NOMATCH
  The regexec() function failed to match
REG_BADPAT
  invalid regular expression
REG_ECOLLATE
  invalid collating element
REG_ECTYPE
  invalid character class
REG_EESCAPE
  \ applied to unescapable character
REG_ESUBREG
  invalid backreference number
REG_EBRACK
  brackets [ ] not balanced
REG_EPAREN
  parentheses ( ) not balanced
REG_EBRACE
  braces { } not balanced
REG_BADBR
  invalid repetition count(s) in { }
REG_ERANGE
  invalid character range in [ ]
REG_ESPACE
  ran out of memory
REG_BADRPT
  ? , * , or + operand invalid
REG_EMPTY
  empty (sub)expression
REG_ASSERT
  cannot happen - you found a bug
REG_INVARG
  invalid argument, e.g. negative-length string
REG_ILLSEQ
  illegal byte sequence (bad multibyte character)

OPTIONS

THIS a compiled regular expression from REGCOMP(3f)
ERRCODE
  the last error code generated by REGCOMP(3f) or REGEXEC(3f)
ERRMSG the error message
ERRMSG_LEN
  size required of ERRMSG to display the entire message

EXAMPLE

Sample program

   program demo_regerror
   use M_regex, only: regex_type, regcomp, regexec, regmatch, regfree, regerror
   type(regex_type)             :: regex
   integer,parameter            :: maxmatch=10
   integer                      :: matches(2,maxmatch)

character(len=:),allocatable :: input_line character(len=:),allocatable :: expression logical :: match

expression= "([0-9\.\-\*\/]+)+" expression= "([0-9\.\-\*\/+)+" ! intentionally bad RE (Regular Expression) input_line= "30*0 250*1 5 6 7" call regcomp(regex,expression,’x’,status=istat) if (istat/=0) then write(*,’("Regex runtime error in regcomp(3f):",a,", expression=",a)’) regerror(regex,istat),expression stop 1 endif match=regexec(regex,input_line,matches,status=istat) if (istat/=0) then write(*,’("Regex runtime error in regexec:(3f)",a)’) regerror(regex,istat) stop 2 endif if(match)then do i=1,maxmatch if(matches(1,i).le.0)exit write(*,*) ’match="’,regmatch(i,input_line,matches),’"’ enddo endif call regfree(regex)

end program demo_regerror

Expected output:

   Regex runtime error in regcomp(3f):brackets ([ ]) not balanced , expression=([0-9\.\-\*\/+)+
   stop 1


regerror (3) April 06, 2020
Generated by manServer 1.08 from 02efd74d-d5b2-452b-8789-8a74e482b61e using man macros.