GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
regex_search(3) rationL User Manual regex_search(3)

regex_search – Searches substring that matches a regular expression

#include <rationl.h>
size_t regex_search(reg_t re, char *input, char **matches[]);
    

regex_search() searches maximal subtring that the regular expression given as parameter matches. Copies all occurences found in the form of a list of string in the output parameter. The output parameter does not need to be allocated but will need to be freed.

re The regular expression compiled using (regex_compile).

input The input string to match against the regular expression

matches This pointer contains a list of string that was allocated by the regex_search function. The string in the list are ordered in order of detection from left to right in the input string. This list will need to be freed by the user.

regex_search() returns the size of the list of string that has been matched by the regular expression.

Programs that returns all function defined in a C source file

#include <err.h>
#include <rationl.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{

if (argc != 2)
errx(1, "No input file found.");
reg_t re = regex_compile(
"\\w+(\\s|\\*)+\\w+\\([ A-Za-z0-9,*]*\\)");
char *line_buf = NULL;
size_t line_buf_size = 0;
int line_count = 0;
ssize_t line_size;
FILE *fp = fopen(argv[1], "r");
if (!fp)
{
errx(EXIT_FAILURE, "Error opening file '%s'\n", argv[1]);
}
char**groups;
while ((line_size = getline(&line_buf, &line_buf_size, fp) >= 0))
{
line_count++;
size_t match_size = regex_search(re, line_buf, &groups);
for (size_t i = 0; i < match_size; i++)
{
printf("%s\n", groups[i]);
free(groups[i]);
}
free(groups);
}
free(line_buf);
fclose(fp);
regex_free(re);
return 0; }
April 5, 2021 rationL 0.1.0

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.