subroutine mymatch(expression,string,expected)
use, intrinsic :: iso_fortran_env, only : ERROR_UNIT
use M_framework__verify, only: unit_check, unit_check_good, unit_check_bad, unit_check_done, unit_check_start, unit_check_level
character(len=*),intent(in) :: expression
character(len=*),intent(in) :: string
logical,intent(in) :: expected
type(regex_type) :: regex
integer,parameter :: maxmatch=10
integer :: matches(2,maxmatch)
logical :: match
integer :: istat
integer :: i
call regcomp(regex,expression,'x',status=istat)
match=.false.
if(istat/=0) then
if(unit_check_level.gt.0)then
write(ERROR_UNIT,'("runtime error in regcomp(3f):",a,", expression=",a)') regerror(regex,istat),expression
endif
else
match=regexec(regex,string,matches,status=istat)
if(istat/=0) then
if(unit_check_level.gt.0)then
write(ERROR_UNIT,'("runtime error in regexec:(3f)",a)') regerror(regex,istat)
endif
else if(match)then
do i=1,maxmatch
if(matches(1,i).le.0)exit
if(unit_check_level.gt.0)then
write(*,*) 'match="',regmatch(i,string,matches),'"'
endif
enddo
endif
endif
call regfree(regex)
call unit_check('M_regex',match .eqv. expected,msg='for REGEX '//trim(expression)//' and string '//trim(string))
end subroutine mymatch