Last modified on 18 September 2010, at 22:35

REBOL Programming/Language Features/Parse/Simple splitting

String parsing involves simple splitting:

parse "this is a string" none
; == ["this" "is" "a" "string"]

By providing NONE as the PARSE rule, we are asking PARSE to break a string into a block of string(s) based on whitespace:

whitespace: charset [#"^A" - #" " "^(7F)^(A0)"]

and common delimiters:

common-delimiter: charset ",;"

To facilitate CSV splitting, quotation marks are handled specially (see the CSV example).

ExamplesEdit

Empty stringEdit

parse "" none
; == []

No delimiters in the input stringEdit

parse "redbluegreen" none
; == ["redbluegreen"]

SpaceEdit

parse "red blue green" none
; == ["red" "blue" "green"]

CommaEdit

parse "red,blue,green" none
; == ["red" "blue" "green"]

TabEdit

parse "red^-blue^-green" none
; == ["red" "blue" "green"]

SemicolonEdit

parse "red;blue;green" none
; == ["red" "blue" "green"]

NewlineEdit

string: {
red
blue  
green
}
parse string none
; == ["red" "blue" "green"]

Leading and trailing whitespaces are ignoredEdit

parse " 1 " none
; == ["1"]

A sequence of whitespaces is equivalent to one whitespaceEdit

parse "1  2" none
; == ["1" "2"]

Leading common delimiter delimits an empty substringEdit

parse ",1" none
; == ["" "1"]

One trailing common delimiter is ignoredEdit

parse "1," none
; == ["1"]

A sequence of common delimiters delimits empty substrings between themEdit

parse "1,,2" none
; == ["1" "" "2"]

CSVEdit

parse {"red","blue","green"} none
; == ["red" "blue" "green"]