More docs for regexps
parent
762485c2ca
commit
8418f8f39a
|
@ -20,9 +20,9 @@ GENERIC: match-index-from ( i string matcher -- index/f )
|
|||
dupd match-index-head
|
||||
[ swap length = ] [ drop f ] if* ;
|
||||
|
||||
:: match-from ( i string matcher -- slice/f )
|
||||
i string length [a,b)
|
||||
[ string matcher match-slice ] map-find drop ;
|
||||
: match-from ( i string matcher -- slice/f )
|
||||
[ [ length [a,b) ] keep ] dip
|
||||
'[ _ _ match-slice ] map-find drop ;
|
||||
|
||||
: match-head ( str matcher -- slice/f )
|
||||
[ 0 ] 2dip match-from ;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
! Copyright (C) 2008, 2009 Doug Coleman, Daniel Ehrenberg.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel strings help.markup help.syntax regexp.matchers ;
|
||||
USING: kernel strings help.markup help.syntax regexp.matchers math ;
|
||||
IN: regexp
|
||||
|
||||
ABOUT: "regexp"
|
||||
|
@ -39,12 +39,11 @@ ARTICLE: { "regexp" "theory" } "The theory of regular expressions"
|
|||
"The Factor regular expression engine was built with the design decision to support negation and intersection at the expense of backreferences. This lets us have a guaranteed linear-time matching algorithm. Systems like Ragel and Lex also use this algorithm, but in the Factor regular expression engine, all other features of regexps are still present." ;
|
||||
|
||||
ARTICLE: { "regexp" "operations" } "Matching operations with regular expressions"
|
||||
{ $subsection all-matches }
|
||||
{ $subsection matches? }
|
||||
{ $subsection match-slice }
|
||||
{ $subsection re-split1 }
|
||||
{ $subsection re-split }
|
||||
{ $subsection re-replace }
|
||||
{ $subsection all-matches }
|
||||
{ $subsection count-matches }
|
||||
{ $subsection re-replace } ;
|
||||
|
||||
|
@ -62,3 +61,27 @@ HELP: R/
|
|||
|
||||
HELP: regexp
|
||||
{ $class-description "The class of regular expressions. To construct these, see " { $link { "regexp" "construction" } } "." } ;
|
||||
|
||||
HELP: matches?
|
||||
{ $values { "string" string } { "matcher" regexp } { "?" "a boolean" } }
|
||||
{ $description "Tests if the string as a whole matches the given regular expression." } ;
|
||||
|
||||
HELP: re-split1
|
||||
{ $values { "string" string } { "matcher" regexp } { "before" string } { "after/f" string } }
|
||||
{ $description "Searches the string for a substring which matches the pattern. If found, the input string is split on the leftmost and longest occurence of the match, and the two halves are given as output. If no match is found, then the input string and " { $link f } " are output." } ;
|
||||
|
||||
HELP: all-matches
|
||||
{ $values { "string" string } { "matcher" regexp } { "seq" "a sequence of slices of the input" } }
|
||||
{ $description "Finds a sequence of disjoint substrings which each match the pattern. It chooses this by finding the leftmost longest match, and then the leftmost longest match which starts after the end of the previous match, and so on." } ;
|
||||
|
||||
HELP: count-matches
|
||||
{ $values { "string" string } { "matcher" regexp } { "n" integer } }
|
||||
{ $description "Counts how many disjoint matches the regexp has in the string, as made unambiguous by " { $link all-matches } "." } ;
|
||||
|
||||
HELP: re-split
|
||||
{ $values { "string" string } { "matcher" regexp } { "seq" "a sequence of slices of the input" } }
|
||||
{ $description "Splits the input string into chunks separated by the regular expression. Each chunk contains no match of the regexp. The chunks are chosen by the strategy of " { $link all-matches } "." } ;
|
||||
|
||||
HELP: re-replace
|
||||
{ $values { "string" string } { "matcher" regexp } { "replacement" string } { "result" string } }
|
||||
{ $description "Replaces substrings which match the input regexp with the given replacement text. The boundaries of the substring are chosen by the strategy used by " { $link all-matches } "." } ;
|
||||
|
|
Loading…
Reference in New Issue