regex
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | regex [2009/06/02 15:52] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | # $EPIC: regex.txt,v 1.8 2009/03/21 05:49:29 zwhite Exp $ | ||
| + | ======Synopsis: | ||
| + | $[[regcomp]](< | ||
| + | $[[regcomp_cs]](< | ||
| + | $[[regexec]](< | ||
| + | $[[regmatches]](< | ||
| + | $[[regerror]](< | ||
| + | $[[regfree]](< | ||
| + | |||
| + | ======Technical: | ||
| + | These functions are an interface to " | ||
| + | |||
| + | $[[regcomp]]() is used to " | ||
| + | The return value is suitable for / | ||
| + | Note that the return value of this function **must** be passed to the | ||
| + | $[[regfree]]() function, to return the allocated resources for the | ||
| + | compiled pattern. The compilation could fail: you should pass the return | ||
| + | value to $[[regerror]]() to check to fetch the error code. | ||
| + | |||
| + | $[[regcomp_cs]]() is the same as regcomp, but the pattern is case sensitive. | ||
| + | |||
| + | $[[regexec]]() is used to match a previously compiled pattern against a | ||
| + | text string. | ||
| + | pattern, and 1 if it does not. | ||
| + | |||
| + | $[[regmatches]]() is used to find substrings within the string. | ||
| + | returns pairs of numbers which can be applied to $[[mid]]() to extract | ||
| + | the respective substring. | ||
| + | empty string. | ||
| + | |||
| + | $[[regerror]]() is used to fetch the error code for the most recently | ||
| + | attempted action on a previously compiled pattern. | ||
| + | |||
| + | $[[regfree]]() is used to return the resources allocated to a compiled | ||
| + | pattern. | ||
| + | to [[regfree]] is an error and may crash the client. | ||
| + | returns the FALSE value. | ||
| + | |||
| + | If you neglect to [[regfree]] something that was returned by | ||
| + | [[regcomp]], | ||
| + | control this, and so if you use these functions, it is your duty to keep | ||
| + | track of this. | ||
| + | |||
| + | Passing a value to [[regexec]], | ||
| + | not previously returned from [[regcomp]] is an error and may crash the | ||
| + | client. | ||
| + | |||
| + | In at least some implementations of the regex calls, regexec will | ||
| + | happily succeed for any pattern that regcomp failed to compile. | ||
| + | necessary to check [[regerror]] after every [[regcomp]] and [[regexec]] | ||
| + | call if you need to know about errors. | ||
| + | |||
| + | ======Practical: | ||
| + | These functions can be very very fast for pattern matching (depending on | ||
| + | implementation) and the notation available is also more powerful than the | ||
| + | standard regex notation. | ||
| + | variations of your name and performance is important to you, then these | ||
| + | functions may meet your needs. | ||
| + | |||
| + | ======Returns: | ||
| + | $[[regcomp]]() returns an opaque l-value suitable for passing to the | ||
| + | other three functions. | ||
| + | $[[regfree]](). \\ | ||
| + | $[[regexec]]() returns 0 or non-zero depending on whether the match worked or | ||
| + | not \\ | ||
| + | $[[regmatches]]() returns a pair of numbers for each substring match. \\ | ||
| + | $[[regerror]]() returns the current error condition for a pattern. \\ | ||
| + | $[[regfree]]() returns the false value. | ||
| + | |||
| + | ======Example: | ||
| + | < | ||
| + | | ||
| + | | ||
| + | if (regerror($pattern)) { | ||
| + | xecho -b Error compiling regex: $regerror($pattern); | ||
| + | }; | ||
| + | if (regexec($pattern $orig_string) == 0) { | ||
| + | xecho -b It matched!; | ||
| + | } else { | ||
| + | xecho -b Regex error: $regerror($pattern); | ||
| + | }; | ||
| + | | ||
| + | </ | ||
| + | |||
| + | When run, this will return: | ||
| + | |||
| + | < | ||
| + | *** It matched! | ||
| + | </ | ||
| + | |||
| + | ======History: | ||
| + | All the functions except [[regmatches]] first appeared in EPIC4-1.029. | ||
| + | The [[regmatches]] function, and its attendant support of subexpressions | ||
| + | first appeared in EPIC4-1.1.3. | ||
| + | |||
regex.txt · Last modified: 2009/06/02 15:52 by 127.0.0.1
