* Executes given regular expression on provided code and returns all * matches that are found. * * @param {String} code Code to execute regular expression on. * @param {Object} regex Regular expression item info from regexList collection. * @return {Array} Returns a l
(code, regexInfo)
| 1011 | * @return {Array} Returns a list of Match objects. |
| 1012 | */ |
| 1013 | function getMatches(code, regexInfo) |
| 1014 | { |
| 1015 | function defaultAdd(match, regexInfo) |
| 1016 | { |
| 1017 | return match[0]; |
| 1018 | }; |
| 1019 | |
| 1020 | var index = 0, |
| 1021 | match = null, |
| 1022 | matches = [], |
| 1023 | func = regexInfo.func ? regexInfo.func : defaultAdd |
| 1024 | ; |
| 1025 | |
| 1026 | while((match = regexInfo.regex.exec(code)) != null) |
| 1027 | { |
| 1028 | var resultMatch = func(match, regexInfo); |
| 1029 | |
| 1030 | if (typeof(resultMatch) == 'string') |
| 1031 | resultMatch = [new sh.Match(resultMatch, match.index, regexInfo.css)]; |
| 1032 | |
| 1033 | matches = matches.concat(resultMatch); |
| 1034 | } |
| 1035 | |
| 1036 | return matches; |
| 1037 | }; |
| 1038 | |
| 1039 | /** |
| 1040 | * Turns all URLs in the code into <a/> tags. |