1% Copyright (C) 2012-2017,2018 John E. Davis 2% 3% This file is part of the S-Lang Library and may be distributed under the 4% terms of the GNU General Public License. See the file COPYING for 5% more information. 6%--------------------------------------------------------------------------- 7import("pcre"); 8 9define pcre_matches () 10{ 11 variable nargs = _NARGS; 12 if (nargs < 2) 13 usage ("\ 14strings = pcre_matches (regexp, str [,pcre_exec_options])\n\ 15Qualifiers:\n\ 16 options=0 pcre_compile options if regexp is a string\n\ 17 offset=0 pcre_exec start matching offset in bytes\n\ 18"; 19 ); 20 variable re, str, options; 21 if (nargs == 2) 22 0; 23 (re, str, options) = (); 24 variable pos = qualifier ("offset", 0); 25 if (typeof (re) != PCRE_Type) 26 { 27 variable compile_options = qualifier ("options", 0); 28 re = pcre_compile (re, options); 29 } 30 31 variable n = pcre_exec (re, str, pos, options); 32 if (n == 0) 33 return NULL; 34 35 variable matches = String_Type[n]; 36 _for (0, n-1, 1) 37 { 38 variable i = (); 39 matches[i] = pcre_nth_substr (re, str, i); 40 } 41 return matches; 42} 43 44$1 = path_concat (path_dirname (__FILE__), "help/pcrefuns.hlp"); 45if (NULL != stat_file ($1)) 46 add_doc_file ($1); 47 48provide("pcre"); 49