| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
Macros | Typedefs | Functions
regex.h File Reference
`#include <wireshark.h>`

Go to the source code of this file.

## Macros
#define | WS_REGEX_CASELESS (1U << 0)
| Enables case-insensitive matching.
#define | WS_REGEX_NEVER_UTF (1U << 1)
| Disables UTF-8 mode, even if requested in the pattern.
#define | WS_REGEX_ANCHORED (1U << 2)
| Anchors the pattern to the start of the subject string.

## Typedefs
typedef struct _ws_regex | ws_regex_t

## Functions
WS_DLL_PUBLIC ws_regex_t * | ws_regex_compile (const char *patt, char **errmsg)
| Compiles a regular expression pattern.
WS_DLL_PUBLIC ws_regex_t * | ws_regex_compile_ex (const char *patt, ssize_t size, char **errmsg, unsigned flags)
| Compiles a regular expression with extended options.
WS_DLL_PUBLIC bool | ws_regex_matches (const ws_regex_t *re, const char *subj)
| Matches a null-terminated subject string against a compiled regex.
WS_DLL_PUBLIC bool | ws_regex_matches_length (const ws_regex_t *re, const char *subj, ssize_t subj_length)
| Matches a subject string of specified length against a compiled regex.
WS_DLL_PUBLIC bool | ws_regex_matches_pos (const ws_regex_t *re, const char *subj, ssize_t subj_length, size_t subj_offset, size_t pos_vect[2])
| Finds the position of a match within a subject string.
WS_DLL_PUBLIC void | ws_regex_free (ws_regex_t *re)
| Frees a compiled regex object.
WS_DLL_PUBLIC const char * | ws_regex_pattern (const ws_regex_t *re)
| Returns the original pattern string from a compiled regex.

## Detailed Description

Wireshark - Network traffic analyzer By Gerald Combs geral.nosp@m.d@wi.nosp@m.resha.nosp@m.rk.o.nosp@m.rg Copyright 1998 Gerald Combs

SPDX-License-Identifier: GPL-2.0-or-later

## Function Documentation

## ◆ ws_regex_compile()

WS_DLL_PUBLIC ws_regex_t * ws_regex_compile | ( | const char * | patt,
|  | char ** | errmsg
| ) |  |

Compiles a regular expression pattern.

Parses and compiles the given null-terminated pattern string into a regex object. On failure, sets an error message in `errmsg`.

Parameters

  patt | The pattern string to compile.
  errmsg | Pointer to a string for error reporting (set on failure).

Returns
  A pointer to the compiled regex object, or NULL on error.

## ◆ ws_regex_compile_ex()

WS_DLL_PUBLIC ws_regex_t * ws_regex_compile_ex | ( | const char * | patt,
|  | ssize_t | size,
|  | char ** | errmsg,
|  | unsigned | flags
| ) |  |

Compiles a regular expression with extended options.

Compiles a pattern of specified length with optional flags for case sensitivity, UTF-8 handling, and anchoring. On failure, sets an error message in `errmsg`.

Parameters

  patt | The pattern string to compile.
  size | Length of the pattern string.
  errmsg | Pointer to a string for error reporting (set on failure).
  flags | Bitmask of WS_REGEX_* options.

Returns
  A pointer to the compiled regex object, or NULL on error.

## ◆ ws_regex_free()

WS_DLL_PUBLIC void ws_regex_free | ( | ws_regex_t * | re | ) |

Frees a compiled regex object.

Releases memory associated with the compiled regex.

Parameters

  re | Pointer to the regex object to free.

## ◆ ws_regex_matches()

WS_DLL_PUBLIC bool ws_regex_matches | ( | const ws_regex_t * | re,
|  | const char * | subj
| ) |  |

Matches a null-terminated subject string against a compiled regex.

Tests whether the subject string matches the compiled pattern.

Parameters

  re | Pointer to the compiled regex object.
  subj | Null-terminated subject string to match.

Returns
  true if the pattern matches, false otherwise.

## ◆ ws_regex_matches_length()

WS_DLL_PUBLIC bool ws_regex_matches_length | ( | const ws_regex_t * | re,
|  | const char * | subj,
|  | ssize_t | subj_length
| ) |  |

Matches a subject string of specified length against a compiled regex.

Tests whether the subject string matches the compiled pattern, using explicit length.

Parameters

  re | Pointer to the compiled regex object.
  subj | Subject string to match.
  subj_length | Length of the subject string in bytes.

Returns
  true if the pattern matches, false otherwise.

## ◆ ws_regex_matches_pos()

WS_DLL_PUBLIC bool ws_regex_matches_pos | ( | const ws_regex_t * | re,
|  | const char * | subj,
|  | ssize_t | subj_length,
|  | size_t | subj_offset,
|  | size_t | pos_vect[2]
| ) |  |

Finds the position of a match within a subject string.

Returns the start and end positions of the first match in `pos_vect`. Handles lookbehind correctly when using `subj_offset`.

Note
  Using a nonzero subj_offset produces different results than passing a pointer to the later offset as subj when the pattern begins with a lookbehind.
  `pos_vect[0]` is the start index, `pos_vect[1]` is the end index. The difference is the match length.

Parameters

  re | Pointer to the compiled regex object.
  subj | Subject string to match.
  subj_length | Length of the subject string.
  subj_offset | Offset into the subject string to begin matching.
  pos_vect | Output array of two size_t values for match positions.

Returns
  true if a match is found, false otherwise.

## ◆ ws_regex_pattern()

WS_DLL_PUBLIC const char * ws_regex_pattern | ( | const ws_regex_t * | re | ) |

Returns the original pattern string from a compiled regex.

Retrieves the pattern used to compile the regex object.

Parameters

  re | Pointer to the compiled regex object.

Returns
  The original pattern string.