---
name: "re_exec"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/re_comp"
---

# re\_exec(3)

regular expression handler

Part of [re\_comp(3)](/re_comp/3.md).

## NAME

**re\_comp**, **re\_exec** – regular expression handler

## LIBRARY

library “libcompat”

## SYNOPSIS

**#include \<unistd.h\>**

*char* *\**\

**re\_comp**(*const char \*s*);

*int*\

**re\_exec**(*const char \*s*);

## DESCRIPTION

This interface is made obsolete by [regex(3)](/regex/3.md).

The **re\_comp**() function compiles a string into an internal form suitable for pattern matching. The **re\_exec**() function checks the argument string against the last string passed to **re\_comp**().

The **re\_comp**() function returns 0 if the string *s* was compiled successfully; otherwise a string containing an error message is returned. If **re\_comp**() is passed 0 or a null string, it returns without changing the currently compiled regular expression.

The **re\_exec**() function returns 1 if the string *s* matches the last compiled regular expression, 0 if the string *s* failed to match the last compiled regular expression, and -1 if the compiled regular expression was invalid (indicating an internal error).

The strings passed to both **re\_comp**() and **re\_exec**() may have trailing or embedded newline characters; they are terminated by NULs. The regular expressions recognized are described in the manual entry for [ed(1)](/ed/1.md), given the above difference.

## DIAGNOSTICS

The **re\_exec**() function returns -1 for an internal error.

The **re\_comp**() function returns “no previous regular expression” or one of the strings generated by [regerror(3)](/regerror/3.md).

## SEE ALSO

[ed(1)](/ed/1.md), [egrep(1)](/egrep/1.md), [ex(1)](/ex/1.md), [fgrep(1)](/fgrep/1.md), [grep(1)](/grep/1.md), [regex(3)](/regex/3.md)

## HISTORY

The **re\_comp**() and **re\_exec**() functions appeared in 4.0BSD.
