%%RegExp with the contents of Str. It returns
%% a list of matched strings if a match was found and
%% nomatch otherwise. The list of matched strings looks
%% like this: [FullMatch, SubMatch1, SubMatch2, ...]
%% where FullMatch is the string matched by the whole
%% regular expression and SubMatchN is the string that
%% matched subexpression no N. Subexpressions are denoted with '(' ')'
%% in the regular expression
%%
%%
Example: %%
%% match("abc01xyz02rst23", "abc[0-9][0-9]"),
%% returns ["abc01"]
%%
%% match("abc01xyz02rst23", "([a-z]+[0-9]+)([a-z]+[0-9]+)([a-z]+[0-9]+)"),
%% returns ["abc01xyz02rst23","abc01","xyz02","rst23"]
%%
%%
%% @end
match(Str, RegExp) ->
match(Str, RegExp, strings).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% @spec match_pos(Str, RegExp) -> nomatch | [{Start,End}]
%% Start = integer()
%% End = integer()
%%
%% @doc This function is equivalent to match/2, but it
%% returns a list of positions instead for a list of strings.
match_pos(Str, RegExp) ->
match(Str, RegExp, pos).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% @spec lmatch(Lines, RegExp) -> nomatch | {[string()],Rest}
%% Lines = [Str]
%% Rest = [Str]
%% Str = string() | [string|binary] | binary
%% RegExp = string() | binary
%%
%% @doc Performs match/2 on each string in Lines. The
%% first match found is returned along with the rest of the
%% Lines. If no match is found, nomatch is
%% returned.
%%
%% @see match/2
%%
%% @end
lmatch([Str|RestLines], RegExp) ->
case match(Str, RegExp) of
nomatch ->
lmatch(RestLines, RegExp);
Match ->
{Match,RestLines}
end;
lmatch([], _) ->
nomatch.
%%%-----------------------------------------------------------------
%%% Internal Functions
match(Str, RegExp, ReturnType) when is_binary(RegExp) ->
Data = [<<(size(RegExp)):32/native,RegExp/binary>>|Str],
return(ReturnType, list_to_binary(Str),port_call(Data));
match(Str, RegExp, ReturnType) when is_list(RegExp) ->
match(Str, list_to_binary(RegExp), ReturnType).
return(_Type,_,[]) -> nomatch;
return(Type, Str, Bin) ->
return_1(Type, Str, Bin, []).
return_1(Type, Str, <