Sponsored Content
Top Forums Programming Wildcard Pattern Matching In C Post 302976678 by Don Cragun on Sunday 3rd of July 2016 07:15:44 PM
Old 07-03-2016
The man page for the regcomp utility (try man 1 regcomp) on your system should tell you everything you need to know. If you get back something similar to:
Code:
No entry for regcomp in section 1 of the manual

(which is what I get on OS X) then your system does not provide any way to do this. You could try building your own regcomp utility, but there is no guarantee that a compiled RE is included in its entirety in the regex_t that is returned by the regcomp()function (and, even if it is, there is no guarantee that that structure can be loaded at a different location in your address space, or copied into the address space of a different process, and still work).

Maybe Jim can give us more details about the system he is using that provides the regcomp utility he is using.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find wildcard .shtml files in wildcard directories and removing them- How's it done?

I'm trying to figure out how to build a small shell script that will find old .shtml files in every /tgp/ directory on the server and delete them if they are older than 10 days... The structure of the paths are like this: /home/domains/www.domain2.com/tgp/ /home/domains/www.domain3.com/tgp/... (1 Reply)
Discussion started by: Neko
1 Replies

2. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies

3. Shell Programming and Scripting

counting the lines matching a pattern, in between two pattern, and generate a tab

Hi all, I'm looking for some help. I have a file (very long) that is organized like below: >Cluster 0 0 283nt, >01_FRYJ6ZM12HMXZS... at +/99% 1 279nt, >01_FRYJ6ZM12HN12A... at +/99% 2 281nt, >01_FRYJ6ZM12HM4TS... at +/99% 3 283nt, >01_FRYJ6ZM12HM946... at +/99% 4 279nt,... (4 Replies)
Discussion started by: d.chauliac
4 Replies

4. UNIX for Dummies Questions & Answers

sed non-greedy pattern matching with wildcard

Toby> cat sample1 This is some arbitrary text before var1, This IS SOME DIFFERENT ARBITRARY TEXT before var2 Toby> sed -e 's/^This .* before //' -e 's/This .* before //' sample1 var2 I need to convert the above text in sample1 so that the output becomes var1, var2 by... (2 Replies)
Discussion started by: TobyNorris
2 Replies

5. UNIX for Dummies Questions & Answers

Find pattern suffix matching pattern

Hi, I am trying to get a result out of this but fails please help. Have two files /tmp/1 & /tmp/hosts. /tmp/1 IP=123.456.789.01 WAS_HOSTNAME=abcdefgh.was.tb.dsdc /tmp/hosts 123.456.789.01 I want this result in /tmp/hosts if hostname is already there dont want duplicate entry. ... (5 Replies)
Discussion started by: rajeshwebspere
5 Replies

6. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

7. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies

8. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

9. Shell Programming and Scripting

Grep and BzGrep with Wildcard in Search Pattern

Hello All, I hope this is the right area. If not, Kindly let me know and I will report in the appropriate spot. I am needing to find a search pattern that will make the * act as Wildcard in the search pattern instead of being literal. The example I am using is bzgrep "to=<*@domain.com>"... (5 Replies)
Discussion started by: mancountry
5 Replies

10. Shell Programming and Scripting

Replace String matching wildcard pattern

Hi, I know how to replace a string with another in a file. But, i wish to replace the below string pattern EncryptedPassword="{gafgfa}]\asffafsf312a" i.e EncryptedPassword="<any random string>" To EncryptedPassword="" i.e remove the random password to a empty string. Can you... (3 Replies)
Discussion started by: mohtashims
3 Replies
REGCOMP(3)						     Linux Programmer's Manual							REGCOMP(3)

NAME
regcomp, regexec, regerror, regfree - POSIX regex functions SYNOPSIS
#include <sys/types.h> #include <regex.h> int regcomp(regex_t *preg, const char *regex, int cflags); int regexec(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size); void regfree(regex_t *preg); POSIX REGEX COMPILING
regcomp is used to compile a regular expression into a form that is suitable for subsequent regexec searches. regcomp is supplied with preg, a pointer to a pattern buffer storage area; regex, a pointer to the null-terminated string and cflags, flags used to determine the type of compilation. All regular expression searching must be done via a compiled pattern buffer, thus regexec must always be supplied with the address of a regcomp initialized pattern buffer. cflags may be the bitwise-or of one or more of the following: REG_EXTENDED Use POSIX Extended Regular Expression syntax when interpreting regex. If not set, POSIX Basic Regular Expression syntax is used. REG_ICASE Do not differentiate case. Subsequent regexec searches using this pattern buffer will be case insensitive. REG_NOSUB Support for substring addressing of matches is not required. The nmatch and pmatch parameters to regexec are ignored if the pattern buffer supplied was compiled with this flag set. REG_NEWLINE Match-any-character operators don't match a newline. A non-matching list ([^...]) not containing a newline does not match a newline. Match-beginning-of-line operator (^) matches the empty string immediately after a newline, regardless of whether eflags, the execu- tion flags of regexec, contains REG_NOTBOL. Match-end-of-line operator ($) matches the empty string immediately before a newline, regardless of whether eflags contains REG_NOTEOL. POSIX REGEX MATCHING
regexec is used to match a null-terminated string against the precompiled pattern buffer, preg. nmatch and pmatch are used to provide information regarding the location of any matches. eflags may be the bitwise-or of one or both of REG_NOTBOL and REG_NOTEOL which cause changes in matching behaviour described below. REG_NOTBOL The match-beginning-of-line operator always fails to match (but see the compilation flag REG_NEWLINE above) This flag may be used when different portions of a string are passed to regexec and the beginning of the string should not be interpreted as the beginning of the line. REG_NOTEOL The match-end-of-line operator always fails to match (but see the compilation flag REG_NEWLINE above) BYTE OFFSETS Unless REG_NOSUB was set for the compilation of the pattern buffer, it is possible to obtain substring match addressing information. pmatch must be dimensioned to have at least nmatch elements. These are filled in by regexec with substring match addresses. Any unused structure elements will contain the value -1. The regmatch_t structure which is the type of pmatch is defined in regex.h. typedef struct { regoff_t rm_so; regoff_t rm_eo; } regmatch_t; Each rm_so element that is not -1 indicates the start offset of the next largest substring match within the string. The relative rm_eo element indicates the end offset of the match. POSIX ERROR REPORTING
regerror is used to turn the error codes that can be returned by both regcomp and regexec into error message strings. regerror is passed the error code, errcode, the pattern buffer, preg, a pointer to a character string buffer, errbuf, and the size of the string buffer, errbuf_size. It returns the size of the errbuf required to contain the null-terminated error message string. If both errbuf and errbuf_size are non-zero, errbuf is filled in with the first errbuf_size - 1 characters of the error message and a terminating null. POSIX PATTERN BUFFER FREEING
Supplying regfree with a precompiled pattern buffer, preg will free the memory allocated to the pattern buffer by the compiling process, regcomp. RETURN VALUE
regcomp returns zero for a successful compilation or an error code for failure. regexec returns zero for a successful match or REG_NOMATCH for failure. ERRORS
The following errors can be returned by regcomp: REG_BADRPT Invalid use of repetition operators such as using `*' as the first character. REG_BADBR Invalid use of back reference operator. REG_EBRACE Un-matched brace interval operators. REG_EBRACK Un-matched bracket list operators. REG_ERANGE Invalid use of the range operator, eg. the ending point of the range occurs prior to the starting point. REG_ECTYPE Unknown character class name. REG_ECOLLATE Invalid collating element. REG_EPAREN Un-matched parenthesis group operators. REG_ESUBREG Invalid back reference to a subexpression. REG_EEND Non specific error. This is not defined by POSIX.2. REG_EESCAPE Trailing backslash. REG_BADPAT Invalid use of pattern operators such as group or list. REG_ESIZE Compiled regular expression requires a pattern buffer larger than 64Kb. This is not defined by POSIX.2. REG_ESPACE The regex routines ran out of memory. CONFORMING TO
POSIX.2 SEE ALSO
regex(7), GNU regex manual GNU
1998-05-08 REGCOMP(3)
All times are GMT -4. The time now is 02:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy