match(3f) - [M_MATCH] find match to a basic regular expression anywhere on input string
(LICENSE:PD)
integer function match(line, pattern)
character(len=*),intent(in) :: line
integer,intent(in) :: pattern(MAXPAT)
Given a BRE(Basic Regular Expression) converted to a pattern return whether an input string matches it.
LIN string to search for a match to the pattern
PAT pattern generated from a BRE using getpat(3f) or makpat(3f).
Sample program:
program demo_match
use :: M_match, only : getpat, match
use :: M_match, only : MAXPAT, MAXARG, MAXLINE, YES, ERR
implicit none
! find _ find patterns in text
integer :: pat(MAXPAT)
character(len=MAXARG-1) :: argument
integer :: stat
integer :: ios
integer :: len_arg
character(len=MAXLINE-2) :: line
call get_command_argument(1, argument,status=stat,length=len_arg)
if(stat.ne.0.or.argument.eq.'')then
write(*,*)"usage: find pattern."
elseif(getpat(argument(:len_arg), pat) .eq. ERR) then
write(*,*)"illegal pattern."
else
INFINITE: do
read(*,'(a)',iostat=ios)line
if(ios.ne.0)exit
if(match(trim(line), pat) .eq. YES) then
write(*,'(*(a))')trim(line)
endif
enddo INFINITE
endif
end program demo_match
John S. Urban
“Software Tools” by Kernighan and Plauger , 1976
Public Domain
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=chr) | :: | lin(maxline) | ||||
integer(kind=chr) | :: | pat(maxpat) |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | lin_str | |||
integer(kind=chr) | :: | pat(maxpat) |