diff --git a/contrib/extract_translations/extract_translations.erl b/contrib/extract_translations/extract_translations.erl
index 488357ba6..ea1d1c76b 100644
--- a/contrib/extract_translations/extract_translations.erl
+++ b/contrib/extract_translations/extract_translations.erl
@@ -281,14 +281,14 @@ build_additional_translators(List) ->
List).
print_translation(File, Line, Str, StrT) ->
- {ok, StrQ, _} = regexp:gsub(Str, "\"", "\\\""),
- {ok, StrTQ, _} = regexp:gsub(StrT, "\"", "\\\""),
+ StrQ = re:replace(Str, "\"", "\\\"", [global, {return, list}]),
+ StrTQ = re:replace(StrT, "\"", "\\\"", [global, {return, list}]),
io:format("#: ~s:~p~nmsgid \"~s\"~nmsgstr \"~s\"~n~n", [File, Line, StrQ, StrTQ]).
print_translation_obsolete(Str, StrT) ->
File = "unknown.erl",
Line = 1,
- {ok, StrQ, _} = regexp:gsub(Str, "\"", "\\\""),
- {ok, StrTQ, _} = regexp:gsub(StrT, "\"", "\\\""),
+ StrQ = re:replace(Str, "\"", "\\\"", [global, {return, list}]),
+ StrTQ = re:replace(StrT, "\"", "\\\"", [global, {return, list}]),
io:format("#: ~s:~p~n#~~ msgid \"~s\"~n#~~ msgstr \"~s\"~n~n", [File, Line, StrQ, StrTQ]).
diff --git a/src/acl.erl b/src/acl.erl
index 7287a0ba4..40231b010 100644
--- a/src/acl.erl
+++ b/src/acl.erl
@@ -301,18 +301,19 @@ match_acl(ACLName, JID, Host) ->
%% String = string() | undefined
%% RegExp = string()
-is_regexp_match(undefined, RegExp) ->
+is_regexp_match(undefined, _RegExp) ->
false;
is_regexp_match(String, RegExp) ->
- case regexp:first_match(String, RegExp) of
+ try re:run(String, RegExp, [{capture, none}]) of
nomatch ->
false;
- {match, _, _} ->
- true;
- {error, ErrDesc} ->
+ match ->
+ true
+ catch
+ _:ErrDesc ->
?ERROR_MSG(
- "Wrong regexp ~p in ACL: ~p",
- [RegExp, lists:flatten(regexp:format_error(ErrDesc))]),
+ "Wrong regexp ~p in ACL:~n~p",
+ [RegExp, ErrDesc]),
false
end.
@@ -321,6 +322,6 @@ is_regexp_match(String, RegExp) ->
%% Glob = string()
is_glob_match(String, Glob) ->
- is_regexp_match(String, regexp:sh_to_awk(Glob)).
+ is_regexp_match(String, xmerl_regexp:sh_to_awk(Glob)).
diff --git a/src/ejabberd_ctl.erl b/src/ejabberd_ctl.erl
index 7919986ae..9e398f8c3 100644
--- a/src/ejabberd_ctl.erl
+++ b/src/ejabberd_ctl.erl
@@ -277,7 +277,7 @@ try_call_command(Args, Auth, AccessCommands) ->
%% @spec (Args::[string()], Auth, AccessCommands) -> string() | integer() | {string(), integer()} | {error, ErrorType}
call_command([CmdString | Args], Auth, AccessCommands) ->
- {ok, CmdStringU, _} = regexp:gsub(CmdString, "-", "_"),
+ CmdStringU = re:replace(CmdString, "-", "_", [global,{return,list}]),
Command = list_to_atom(CmdStringU),
case ejabberd_commands:get_command_format(Command) of
{error, command_unknown} ->
@@ -673,13 +673,13 @@ filter_commands(All, SubString) ->
end.
filter_commands_regexp(All, Glob) ->
- RegExp = regexp:sh_to_awk(Glob),
+ RegExp = xmerl_regexp:sh_to_awk(Glob),
lists:filter(
fun(Command) ->
- case regexp:first_match(Command, RegExp) of
- {match, _, _} ->
+ case re:run(Command, RegExp, [{capture, none}]) of
+ match ->
true;
- _ ->
+ nomatch ->
false
end
end,
diff --git a/src/ejabberd_s2s_in.erl b/src/ejabberd_s2s_in.erl
index 6a84e2202..590b322f8 100644
--- a/src/ejabberd_s2s_in.erl
+++ b/src/ejabberd_s2s_in.erl
@@ -735,11 +735,11 @@ match_labels([DL | DLabels], [PL | PLabels]) ->
orelse (C == $-) orelse (C == $*)
end, PL) of
true ->
- Regexp = regexp:sh_to_awk(PL),
- case regexp:match(DL, Regexp) of
- {match, _, _} ->
+ Regexp = xmerl_regexp:sh_to_awk(PL),
+ case re:run(DL, Regexp, [{capture, none}]) of
+ match ->
match_labels(DLabels, PLabels);
- _ ->
+ nomatch ->
false
end;
false ->
diff --git a/src/eldap/eldap_filter.erl b/src/eldap/eldap_filter.erl
index 46510e0d6..d0c795958 100644
--- a/src/eldap/eldap_filter.erl
+++ b/src/eldap/eldap_filter.erl
@@ -182,7 +182,7 @@ parse_attr(less, {Name, Value}, ListOfSubValues) ->
eldap:lessOrEqual(Name, NewValue);
parse_attr(equal, {Name, Value}, ListOfSubValues) ->
- {ok, RegSList} = regexp:split(remove_extra_asterisks(Value), "[*]"),
+ RegSList = re:split(remove_extra_asterisks(Value), "[*]", [{return, list}]),
Pattern = case [do_sub(X, ListOfSubValues) || X <- RegSList] of
[Head | Tail] when Tail /= [] ->
{Head, lists:sublist(Tail, length(Tail)-1), lists:last(Tail)};
@@ -228,14 +228,15 @@ do_sub(S, [{RegExp, New, Times} | T]) ->
do_sub(Result, T).
do_sub(S, {RegExp, New}, Iter) ->
- case regexp:sub(S, RegExp, New) of
- {ok, NewS, 0} ->
+ try re:replace(S, RegExp, New, [{return, list}]) of
+ NewS when NewS == S ->
NewS;
- {ok, NewS, _} when Iter =< ?MAX_RECURSION ->
+ NewS when Iter =< ?MAX_RECURSION ->
do_sub(NewS, {RegExp, New}, Iter+1);
- {ok, _, _} when Iter > ?MAX_RECURSION ->
- throw({regexp, max_substitute_recursion});
- _ ->
+ _ when Iter > ?MAX_RECURSION ->
+ throw({regexp, max_substitute_recursion})
+ catch
+ _:_ ->
throw({regexp, bad_regexp})
end;
@@ -243,14 +244,15 @@ do_sub(S, {_, _, N}, _) when N<1 ->
S;
do_sub(S, {RegExp, New, Times}, Iter) ->
- case regexp:sub(S, RegExp, New) of
- {ok, NewS, 0} ->
+ try re:replace(S, RegExp, New, [{return, list}]) of
+ NewS when NewS == S ->
NewS;
- {ok, NewS, _} when Iter < Times ->
+ NewS when Iter < Times ->
do_sub(NewS, {RegExp, New, Times}, Iter+1);
- {ok, NewS, _} ->
- NewS;
- _ ->
+ NewS ->
+ NewS
+ catch
+ _:_ ->
throw({regexp, bad_regexp})
end.
diff --git a/src/eldap/eldap_utils.erl b/src/eldap/eldap_utils.erl
index bf9cf1567..0459bee05 100644
--- a/src/eldap/eldap_utils.erl
+++ b/src/eldap/eldap_utils.erl
@@ -89,8 +89,8 @@ get_user_part(String, Pattern) ->
{'EXIT', _} ->
{error, badmatch};
Result ->
- case regexp:sub(Pattern, "%u", Result) of
- {ok, String, _} -> {ok, Result};
+ case re:replace(Pattern, "%u", Result, [{return, list}]) of
+ String -> {ok, Result};
_ -> {error, badmatch}
end
end.
diff --git a/src/gen_mod.erl b/src/gen_mod.erl
index a37ec51e6..df1ccf0ea 100644
--- a/src/gen_mod.erl
+++ b/src/gen_mod.erl
@@ -173,11 +173,11 @@ get_module_opt(Host, Module, Opt, Default) ->
get_module_opt_host(Host, Module, Default) ->
Val = get_module_opt(Host, Module, host, Default),
- element(2, regexp:gsub(Val, "@HOST@", Host)).
+ re:replace(Val, "@HOST@", Host, [global,{return,list}]).
get_opt_host(Host, Opts, Default) ->
Val = get_opt(host, Opts, Default),
- element(2, regexp:gsub(Val, "@HOST@", Host)).
+ re:replace(Val, "@HOST@", Host, [global,{return,list}]).
loaded_modules(Host) ->
ets:select(ejabberd_modules,
diff --git a/src/mod_configure.erl b/src/mod_configure.erl
index dd8040eca..4f39ccd49 100644
--- a/src/mod_configure.erl
+++ b/src/mod_configure.erl
@@ -524,7 +524,7 @@ get_local_items({_, Host}, ["all users", [$@ | Diap]], _Server, _Lang) ->
Users ->
SUsers = lists:sort([{S, U} || {U, S} <- Users]),
case catch begin
- {ok, [S1, S2]} = regexp:split(Diap, "-"),
+ [S1, S2] = re:split(Diap, "-", [{return, list}]),
N1 = list_to_integer(S1),
N2 = list_to_integer(S2),
Sub = lists:sublist(SUsers, N1, N2 - N1 + 1),
diff --git a/src/mod_muc/mod_muc_log.erl b/src/mod_muc/mod_muc_log.erl
index 2456c1324..1dbd27474 100644
--- a/src/mod_muc/mod_muc_log.erl
+++ b/src/mod_muc/mod_muc_log.erl
@@ -415,11 +415,11 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) ->
io_lib:format("~s~s~s
",
[Nick, ?T(" has set the subject to: "), htmlize(T,NoFollow,FileFormat)]);
{body, T} ->
- case {regexp:first_match(T, "^/me\s"), Nick} of
+ case {re:run(T, "^/me\s", [{capture, none}]), Nick} of
{_, ""} ->
io_lib:format("~s
",
[htmlize(T,NoFollow,FileFormat)]);
- {{match, _, _}, _} ->
+ {match, _} ->
io_lib:format("~s ~s
",
[Nick, string:substr(htmlize(T,FileFormat), 5)]);
{nomatch, _} ->
@@ -664,8 +664,7 @@ fw(F, S, O, FileFormat) ->
html ->
S1;
plaintext ->
- {ok, Res, _} = regexp:gsub(S1, "<[^>]*>", ""),
- Res
+ re:replace(S1, "<[^>]*>", "", [global,{return,list}])
end,
io:format(F, S2, []).
@@ -794,15 +793,20 @@ htmlize(S1, NoFollow, _FileFormat) ->
S2_list).
htmlize2(S1, NoFollow) ->
- S2 = element(2, regexp:gsub(S1, "\\&", "\\&")),
- S3 = element(2, regexp:gsub(S2, "<", "\\<")),
- S4 = element(2, regexp:gsub(S3, ">", "\\>")),
- S5 = element(2, regexp:gsub(S4, "((http|https|ftp)://|(mailto|xmpp):)[^] )\'\"}]+",
- link_regexp(NoFollow))),
- %% Remove 'right-to-left override' unicode character 0x202e
- S6 = element(2, regexp:gsub(S5, " ", "\\ \\ ")),
- S7 = element(2, regexp:gsub(S6, "\\t", "\\ \\ \\ \\ ")),
- element(2, regexp:gsub(S7, [226,128,174], "[RLO]")).
+ ReplacementRules =
+ [{"\\&", "\\&"},
+ {"<", "\\<"},
+ {">", "\\>"},
+ {"((http|https|ftp)://|(mailto|xmpp):)[^] )\'\"}]+", link_regexp(NoFollow)},
+ {" ", "\\ \\ "},
+ {"\\t", "\\ \\ \\ \\ "},
+ {[226,128,174], "[RLO]"}], %% Remove 'right-to-left override' unicode character 0x202e
+ lists:foldl(
+ fun({RegExp, Replace}, Acc) ->
+ re:replace(Acc, RegExp, Replace)
+ end,
+ S1,
+ ReplacementRules).
%% Regexp link
%% Add the nofollow rel attribute when required
diff --git a/src/mod_shared_roster.erl b/src/mod_shared_roster.erl
index da7b72357..6d577be58 100644
--- a/src/mod_shared_roster.erl
+++ b/src/mod_shared_roster.erl
@@ -561,8 +561,8 @@ is_user_in_group({_U, S} = US, Group, Host) ->
%% @spec (Host::string(), {User::string(), Server::string()}, Group::string()) -> {atomic, ok}
add_user_to_group(Host, US, Group) ->
{LUser, LServer} = US,
- case regexp:match(LUser, "^@.+@$") of
- {match,_,_} ->
+ case re:run(LUser, "^@.+@$", [{capture, none}]) of
+ match ->
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
AllUsersOpt =
case LUser == "@all@" of
@@ -593,8 +593,8 @@ push_displayed_to_user(LUser, LServer, Group, Host, Subscription) ->
remove_user_from_group(Host, US, Group) ->
GroupHost = {Group, Host},
{LUser, LServer} = US,
- case regexp:match(LUser, "^@.+@$") of
- {match,_,_} ->
+ case re:run(LUser, "^@.+@$", [{capture, none}]) of
+ match ->
GroupOpts = mod_shared_roster:get_group_opts(Host, Group),
NewGroupOpts =
case LUser of
@@ -856,7 +856,7 @@ shared_roster_group(Host, Group, Query, Lang) ->
[]
end ++ [[us_to_list(Member), $\n] || Member <- Members],
FDisplayedGroups = [[DG, $\n] || DG <- DisplayedGroups],
- DescNL = length(element(2, regexp:split(Description, "\n"))),
+ DescNL = length(re:split(Description, "\n", [{return, list}])),
FGroup =
?XAE("table", [?XMLATTR('class', <<"withtextareas">>)],
[?XE("tbody",
diff --git a/src/web/ejabberd_web_admin.erl b/src/web/ejabberd_web_admin.erl
index 85a3a2cac..1f47c42e8 100644
--- a/src/web/ejabberd_web_admin.erl
+++ b/src/web/ejabberd_web_admin.erl
@@ -1232,13 +1232,13 @@ acl_spec_select(ID, Opt) ->
term_to_string(T) ->
StringParagraph = lists:flatten(io_lib:format("~1000000p", [T])),
%% Remove from the string all the carriage returns characters
- {ok, StringLine, _} = regexp:gsub(StringParagraph, "\\n ", ""),
+ StringLine = re:replace(StringParagraph, "\\n ", "", [global,{return,list}]),
StringLine.
%% @spec (T::any(), Cols::integer()) -> {NumLines::integer(), Paragraph::string()}
term_to_paragraph(T, Cols) ->
Paragraph = erl_prettypr:format(erl_syntax:abstract(T), [{paper, Cols}]),
- {ok, FieldList} = regexp:split(Paragraph, "\n"),
+ FieldList = re:split(Paragraph, "\n", [{return, list}]),
NumLines = length(FieldList),
{NumLines, Paragraph}.
@@ -1563,7 +1563,7 @@ list_users_parse_query(Query, Host) ->
list_users_in_diapason(Host, Diap, Lang, URLFunc) ->
Users = ejabberd_auth:get_vh_registered_users(Host),
SUsers = lists:sort([{S, U} || {U, S} <- Users]),
- {ok, [S1, S2]} = regexp:split(Diap, "-"),
+ [S1, S2] = re:split(Diap, "-", [{return, list}]),
N1 = list_to_integer(S1),
N2 = list_to_integer(S2),
Sub = lists:sublist(SUsers, N1, N2 - N1 + 1),