REBOL Document

Parse - Function Summary


Summary:

Parses a series according to rules.

Usage:

parse input rules

Arguments:

input - Input series to parse (must be: series)

rules - Rules to parse by (must be: block string none)

Refinements:

/all - Parses all chars including spaces.

/case - Uses case-sensitive comparison.

Description:

Parsing provides a means of recognizing a series of characters that appear in a particular order. Essentially, it is a method of finding and matching patterns. The rules argument supplies a block of grammar productions that are to be matched.

There is also a simple parse mode that does not require rules, but takes a string of characters to use for splitting up the input string.

Parse also works in conjunction with bitsets (charset) to specify groups of special characters.

The result returned from a simple parse is a block of values. For rule-based parses, it returns TRUE if the parse succeeded through the end of the input string.

The /ALL refinement indicates that all the characters within a string will be parsed. Otherwise, spaces, tabs, newlines, and other non-printable characters will be treated as spaces.

The /CASE refinement specifies that a string is to be parsed case sensitive.


 print parse "divide on spaces" none
 divide on spaces


 print parse "Harry Haiku, 264 River Rd., Ukiah, 95482" ","
 Harry Haiku 264 River Rd. Ukiah 95482


 page: read http://hq.rebol.net
 parse page [thru <title> copy title to </title>]
 print title
 Headquarters Intranet


 digits: charset "0123456789"
 area-code: ["(" 3 digits ")"]
 phone-num: [3 digits "-" 4 digits]
 print parse "(707)467-8000" [[area-code | none] phone-num]
 true

Related:

trim - Removes whitespace from a string. Default removes from head and tail.

AltStyle によって変換されたページ (->オリジナル) /