\hypertarget{namespacedc__regex}{}\section{dc\+\_\+regex Module Reference}
\label{namespacedc__regex}\index{dc\+\_\+regex@{dc\+\_\+regex}}


Provide simple regular expression subroutine\+: \textquotesingle{}match\textquotesingle{}.  


\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacedc__regex_abc5c6d1c941d8689bdf6e32a6b919b25}{match} (pattern, text, start, length)
\end{DoxyCompactItemize}


\subsection{Detailed Description}
Provide simple regular expression subroutine\+: \textquotesingle{}match\textquotesingle{}. 

\begin{DoxyAuthor}{Author}
Youhei S\+A\+S\+A\+KI 
\end{DoxyAuthor}
\begin{DoxyCopyright}{Copyright}
Copyright (C) G\+FD Dennou Club, 2000-\/2016. All rights reserved. ~\newline
 License is B\+S\+D-\/2-\/\+Clause. see \hyperlink{COPYRIGHT}{C\+O\+P\+Y\+R\+I\+G\+HT} in detail 
\end{DoxyCopyright}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacedc__regex_abc5c6d1c941d8689bdf6e32a6b919b25}\label{namespacedc__regex_abc5c6d1c941d8689bdf6e32a6b919b25}} 
\index{dc\+\_\+regex@{dc\+\_\+regex}!match@{match}}
\index{match@{match}!dc\+\_\+regex@{dc\+\_\+regex}}
\subsubsection{\texorpdfstring{match()}{match()}}
{\footnotesize\ttfamily subroutine, public dc\+\_\+regex\+::match (\begin{DoxyParamCaption}\item[{character(len = $\ast$), intent(in)}]{pattern,  }\item[{character(len = $\ast$), intent(in)}]{text,  }\item[{integer, intent(out)}]{start,  }\item[{integer, intent(out)}]{length }\end{DoxyParamCaption})}


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em pattern} & 例 
\begin{DoxyCode}
\textcolor{keyword}{program} regex\_test
  \textcolor{keywordtype}{use }\hyperlink{namespacedc__regex}{dc\_regex}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__regex_abc5c6d1c941d8689bdf6e32a6b919b25}{match}
  \textcolor{keywordtype}{use }\hyperlink{namespacedc__types}{dc\_types}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__types_a6d28eb015ba84292a06f4ff25165b376}{token}
  \textcolor{keywordtype}{implicit none}

  \textcolor{keywordtype}{integer}:: start, length
  \textcolor{keywordtype}{character(TOKEN)} :: pattern, text
\textcolor{keywordflow}{continue}
  pattern = \textcolor{stringliteral}{"->"}
  text    = \textcolor{stringliteral}{"time->0.0,x->hoge"}
  \textcolor{keyword}{call }\hyperlink{namespacedc__regex_abc5c6d1c941d8689bdf6e32a6b919b25}{match}(trim(pattern), trim(text), start, length)
  \textcolor{keyword}{call }formatted\_print

  pattern = \textcolor{stringliteral}{"^##+"}
  text    = \textcolor{stringliteral}{"####### hoge"}
  \textcolor{keyword}{call }\hyperlink{namespacedc__regex_abc5c6d1c941d8689bdf6e32a6b919b25}{match}(trim(pattern), trim(text), start, length)
  \textcolor{keyword}{call }formatted\_print

  pattern = \textcolor{stringliteral}{"@+$"}
  text    = \textcolor{stringliteral}{"# hoge @@@"}
  \textcolor{keyword}{call }\hyperlink{namespacedc__regex_abc5c6d1c941d8689bdf6e32a6b919b25}{match}(trim(pattern), trim(text), start, length)
  \textcolor{keyword}{call }formatted\_print

\textcolor{keyword}{contains}
\textcolor{keyword}{  subroutine }formatted\_print
    \textcolor{keywordtype}{use }dc\_string\textcolor{keywordtype}{, only}: printf
    \textcolor{keyword}{call }printf(fmt=\textcolor{stringliteral}{'pattern= %c : text= %c : start= %d : length= %d'}, &
      & c1=trim(pattern), c2=trim(text), i=(/start, length/))
\textcolor{keyword}{  end subroutine }formatted\_print

\textcolor{keyword}{end program }regex\_test
\end{DoxyCode}
 このプログラムを実行することで以下の出力が得られるはずです。 \begin{DoxyVerb} pattern= -> : text= time->0.0,x->hoge : start= 5 : length= 2
 pattern= ^##+ : text= ####### hoge : start= 1 : length= 7
 pattern= @+$ : text= # hoge @@@ : start= 8 : length= 3 \end{DoxyVerb}
 \\
\hline
\mbox{\tt in}  & {\em text} & 例 
\begin{DoxyCode}
\textcolor{keyword}{program} regex\_test
  \textcolor{keywordtype}{use }\hyperlink{namespacedc__regex}{dc\_regex}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__regex_abc5c6d1c941d8689bdf6e32a6b919b25}{match}
  \textcolor{keywordtype}{use }\hyperlink{namespacedc__types}{dc\_types}\textcolor{keywordtype}{, only}: \hyperlink{namespacedc__types_a6d28eb015ba84292a06f4ff25165b376}{token}
  \textcolor{keywordtype}{implicit none}

  \textcolor{keywordtype}{integer}:: start, length
  \textcolor{keywordtype}{character(TOKEN)} :: pattern, text
\textcolor{keywordflow}{continue}
  pattern = \textcolor{stringliteral}{"->"}
  text    = \textcolor{stringliteral}{"time->0.0,x->hoge"}
  \textcolor{keyword}{call }\hyperlink{namespacedc__regex_abc5c6d1c941d8689bdf6e32a6b919b25}{match}(trim(pattern), trim(text), start, length)
  \textcolor{keyword}{call }formatted\_print

  pattern = \textcolor{stringliteral}{"^##+"}
  text    = \textcolor{stringliteral}{"####### hoge"}
  \textcolor{keyword}{call }\hyperlink{namespacedc__regex_abc5c6d1c941d8689bdf6e32a6b919b25}{match}(trim(pattern), trim(text), start, length)
  \textcolor{keyword}{call }formatted\_print

  pattern = \textcolor{stringliteral}{"@+$"}
  text    = \textcolor{stringliteral}{"# hoge @@@"}
  \textcolor{keyword}{call }\hyperlink{namespacedc__regex_abc5c6d1c941d8689bdf6e32a6b919b25}{match}(trim(pattern), trim(text), start, length)
  \textcolor{keyword}{call }formatted\_print

\textcolor{keyword}{contains}
\textcolor{keyword}{  subroutine }formatted\_print
    \textcolor{keywordtype}{use }dc\_string\textcolor{keywordtype}{, only}: printf
    \textcolor{keyword}{call }printf(fmt=\textcolor{stringliteral}{'pattern= %c : text= %c : start= %d : length= %d'}, &
      & c1=trim(pattern), c2=trim(text), i=(/start, length/))
\textcolor{keyword}{  end subroutine }formatted\_print

\textcolor{keyword}{end program }regex\_test
\end{DoxyCode}
 このプログラムを実行することで以下の出力が得られるはずです。 \begin{DoxyVerb} pattern= -> : text= time->0.0,x->hoge : start= 5 : length= 2
 pattern= ^##+ : text= ####### hoge : start= 1 : length= 7
 pattern= @+$ : text= # hoge @@@ : start= 8 : length= 3 \end{DoxyVerb}
 \\
\hline
\end{DoxyParams}


Definition at line 267 of file dc\+\_\+regex.\+f90.


\begin{DoxyCode}
267     \textcolor{comment}{!}
279     \textcolor{comment}{!}
320     \textcolor{keywordtype}{implicit none}
321     \textcolor{keywordtype}{character(len = *)}, \textcolor{keywordtype}{intent(in)}:: pattern, text
322     \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(out)}:: start, length
323     \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{allocatable}:: ipattern(:)
324     \textcolor{keywordtype}{integer}:: text\_length
325     \textcolor{keywordflow}{continue}
326     \textcolor{comment}{! 空 pattern は空文字列に適合}
327     \textcolor{keywordflow}{if} (len(pattern) <= 0) \textcolor{keywordflow}{then}
328       length = 0
329       start = 1
330       \textcolor{keywordflow}{return}
331 \textcolor{keywordflow}{    endif}
332     \textcolor{comment}{! メタキャラクタの認識}
333     \textcolor{keyword}{allocate}(ipattern(len(pattern) + 2))
334     \textcolor{keyword}{call }preprocess\_pattern(pattern, ipattern)
335     \textcolor{comment}{! 頭寄せ指定のある場合}
336     \textcolor{keywordflow}{if} (ipattern(1) == sym\_headfix) \textcolor{keywordflow}{then}
337       start = 1
338       \textcolor{keyword}{call }match\_here(ipattern(2: ), text, length)
339       \textcolor{keywordflow}{if} (length < 0) \textcolor{keywordflow}{goto} 995
340       \textcolor{keywordflow}{goto} 999
341 \textcolor{keywordflow}{    endif}
342     \textcolor{comment}{! 最左原理}
343     text\_length = len(text)
344     \textcolor{keywordflow}{do}, start = 1, text\_length + 1
345       \textcolor{keyword}{call }match\_here(ipattern, text(start:text\_length), length)
346       \textcolor{keywordflow}{if} (length >= 0) \textcolor{keywordflow}{goto} 999
347 \textcolor{keywordflow}{    end do}
348     \textcolor{comment}{! みつからない場合}
349 995 \textcolor{keywordflow}{continue}
350     start = 0
351     length = -1
352 999 \textcolor{keywordflow}{continue}
353     \textcolor{keyword}{deallocate}(ipattern)
\end{DoxyCode}
