diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-09-11 19:55:32 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-09-11 19:55:32 -0700 |
commit | fc5935a9fe816d64291e66b1ca5133a27f5f0230 (patch) | |
tree | ffd7371d6ee3817aedf45d63e6606f072a16ac83 /txr.1 | |
parent | 6417918274d7d7d8d5b7bb675906f8e38d25c073 (diff) | |
download | txr-fc5935a9fe816d64291e66b1ca5133a27f5f0230.tar.gz txr-fc5935a9fe816d64291e66b1ca5133a27f5f0230.tar.bz2 txr-fc5935a9fe816d64291e66b1ca5133a27f5f0230.zip |
regex: new function, regex-prefix-match.
This new function allows a program to determine whether a
given string is the prefix of any of the strings denoted by a
regular expression; or, in alternative words, whether a given
string is the prefix of a possibly longer string which matches
a regular expression.
* regex.c (regex_machine_infer_init_state): New static
function.
(regex_prefix_match): New function.
(regex_init): regex-prefix-match intrinsic registered.
regex.h (regex_prefix_match): Declared.
* txr.1: Documented.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 69 |
1 files changed, 69 insertions, 0 deletions
@@ -37915,6 +37915,75 @@ the matching substring of (match-regex-right-substring "ac" #/c*/) -> "c" .cble +.coNP Function @ regex-prefix-match +.synb +.mets (regex-prefix-match < regex < string <> [ position ]) +.syne +.desc +The +.code regex-prefix-match +determines whether the input string might +might be the prefix of a string which matches regular expression +.metn regex . + +The result is true if the input string matches +.meta regex +exactly. However, it is also true in situations in which +the input string doesn't match +.metn regex , +yet can be extended with one or more additional characters beyond the end such +that the extended string +.B does +match. + +The +.meta string +argument must be a character string. The function takes the input string to be +the suffix of +.meta string +which starts at the character position indicated by the +.meta position +argument. If that argument is omitted, then +.meta string +is taken as the input in its entirety. Negative values index backwards from +the end of +.meta string +according to the usual conventions elsewhere in the library. + +Note: this function is not to be confused for the semantics +of a regex matching a prefix of a string: that capability is +provided by the functions +.codn match-regex , +.codn m^ , +.codn r^ , +.code f^ +and +.codn fr^ . + +.TP* Examples: + +.cblk + ;; The empty string is not a viable prefix match for + ;; a regex that matches no strings at all: + (regex-prefix-match #/~.*/ "") -> nil + (regex-prefix-match #/[]/ "") -> nil + + ;; The empty string is a viable prefix of any regex + ;; which matches at least one string: + (regex-prefix-match #// "") -> t + (regex-prefix-match #/abc/ "") -> t + + ;; This string doesn't match the regex because + ;; it doesn't end in b, but is a viable prefix: + (regex-prefix-match #/a*b/ "aa") -> t + + (regex-prefix-match #/a*b/ "ab") -> t + + (regex-prefix-match #/a*b/ "ac") -> nil + + (regex-prefix-match #/a*b/ "abc") -> nil +.cble + .coNP Function @ regsub .synb .mets (regsub >> { regex | << function } < replacement << string ) |