Skip to content

Commit

Permalink
/e: Set RZ_REGEX_MULTILINE for ^ and $ (#4868)
Browse files Browse the repository at this point in the history
* `/e`: Set `RZ_REGEX_MULTILINE` for `^` and `$`
* Add note in `/e` help for `^` and `$`

Co-authored-by: Rot127 <[email protected]>
  • Loading branch information
kazarmy and Rot127 authored Jan 29, 2025
1 parent 8d391b7 commit 303b39e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion librz/core/cmd/cmd_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static const char *help_msg_slash[] = {
"/b", "", "search backwards, command modifier, followed by other command",
"/c", "[?][adr]", "search for crypto materials",
"/d", " 101112", "search for a deltified sequence of bytes",
"/e", " /pattern/[i]", "match regular expression",
"/e", " /pattern/[i]", "match regular expression (beginning-of-string for ^ and $ is '\\0')",
"/E", " esil-expr", "offset matching given esil expressions $$ = here",
"/f", "", "search forwards, (command modifier)",
"/F", " file [off] [sz]", "search contents of file with offset and size",
Expand Down
2 changes: 1 addition & 1 deletion librz/search/regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RZ_API int rz_search_regexp_update(RzSearch *s, ut64 from, const ut8 *buf, int l
rz_regex_set_nul_as_newline(ccontext);

rz_list_foreach (s->kws, iter, kw) {
int cflags = RZ_REGEX_EXTENDED;
int cflags = RZ_REGEX_EXTENDED | RZ_REGEX_MULTILINE;

if (kw->icase) {
cflags |= RZ_REGEX_CASELESS;
Expand Down
22 changes: 18 additions & 4 deletions test/db/cmd/regexp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,29 @@ CMDS=<<EOF
w abcd
w bcccde @ 0x10
e scr.color=1
echo -- 1 --
/e /b.*d/
echo ----
echo -- 2 --
/e /b.*D/
echo ----
echo -- 3 --
/e /b.*D/i
echo -- 4 --
/e /b.*d$/
echo -- 5 --
/e /^b.*d/
EOF
EXPECT=<<EOF
-- 1 --
0x00000001 hit0_0 .abcdbccc.
0x00000010 hit0_1 .abcdbcccde.
----
----
-- 2 --
-- 3 --
0x00000001 hit2_0 .abcdbccc.
0x00000010 hit2_1 .abcdbcccde.
-- 4 --
0x00000001 hit3_0 .abcdbccc.
-- 5 --
0x00000010 hit4_0 .abcdbcccde.
EOF
EXPECT_ERR=<<EOF
Searching in [0x0-0x200]
Expand All @@ -72,5 +82,9 @@ Searching in [0x0-0x200]
hits: 0
Searching in [0x0-0x200]
hits: 2
Searching in [0x0-0x200]
hits: 1
Searching in [0x0-0x200]
hits: 1
EOF
RUN
Expand Down

0 comments on commit 303b39e

Please sign in to comment.