(************************************************************ regexp_question.ml Created : Sat Jun 28 12:47:15 2003 Last modified: Sat Jun 28 12:56:46 2003 Compile: ocamlc str.cma regexp_question.ml -o regexp_question # FTP Directory: sources/ocaml # ************************************************************) (** @author Takashi Masuyama ? でマッチしなかった場合にそのグループにマッチした文字列を 取り出す (Str.matched_group) と Not_found 例外が投げられる。 (マニュアルの Str.matched_group の説明に書いてある ) *) let _ = let data = "abc" in let regexp = Str.regexp "\\(A\\)?abc" in if Str.string_match regexp data 0 then print_endline ("Matched "^(Str.matched_group 1 data)) else print_endline "Not matched"