From 4e75c1bf32d0ed9155de74d77e1019a230cc698c Mon Sep 17 00:00:00 2001 From: lewisl Date: Sat, 3 Nov 2018 15:43:42 -0700 Subject: [PATCH 1/4] Update the Regex section of strings.md. This adds a brief description and example of using the Regex constructor to create regex strings programmatically. --- doc/src/manual/strings.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/doc/src/manual/strings.md b/doc/src/manual/strings.md index 9e3606c2e10b0..097c4182b0c9d 100644 --- a/doc/src/manual/strings.md +++ b/doc/src/manual/strings.md @@ -936,6 +936,33 @@ ERROR: syntax: invalid escape sequence Triple-quoted regex strings, of the form `r"""..."""`, are also supported (and may be convenient for regular expressions containing quotation marks or newlines). +The Regex() constructor may be used to create a valid regex string programmatically. This permits using the contents of string variables and other string operations when constructing the regex string. Any of the regex codes above can be used within the single string argument to Regex(). Here are some examples: + +```julia-repl +julia> using Dates + +julia> d = Date(1962,7,10) +1962-07-10 + +julia> regex_d = Regex("Day " * string(day(d))) +r"Day 10" + +julia> match(regex_d,"It happened on Day 10") +RegexMatch("Day 10") + +julia> name = "Jon" +"Jon" + +julia> regex_name = Regex("[\"( ]$name[\") ]") # interpolate value of name +r"[\"( ]Jon[\") ]" + +julia> match(regex_name," Jon ") +RegexMatch(" Jon ") + +julia> match(regex_name,"[Jon]") === nothing +true +``` + ## [Byte Array Literals](@id man-byte-array-literals) Another useful non-standard string literal is the byte-array string literal: `b"..."`. This From f5fb96311582bac4b9f911e39d2541f54e6d1e47 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 13 Nov 2018 10:14:21 -0800 Subject: [PATCH 2/4] Update doc/src/manual/strings.md Co-Authored-By: lewisl --- doc/src/manual/strings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/manual/strings.md b/doc/src/manual/strings.md index 097c4182b0c9d..6ba09bbf1a178 100644 --- a/doc/src/manual/strings.md +++ b/doc/src/manual/strings.md @@ -936,7 +936,7 @@ ERROR: syntax: invalid escape sequence Triple-quoted regex strings, of the form `r"""..."""`, are also supported (and may be convenient for regular expressions containing quotation marks or newlines). -The Regex() constructor may be used to create a valid regex string programmatically. This permits using the contents of string variables and other string operations when constructing the regex string. Any of the regex codes above can be used within the single string argument to Regex(). Here are some examples: +The `Regex()` constructor may be used to create a valid regex string programmatically. This permits using the contents of string variables and other string operations when constructing the regex string. Any of the regex codes above can be used within the single string argument to `Regex()`. Here are some examples: ```julia-repl julia> using Dates From 7d454444da583bbfdefd49526c738b03b4d753cd Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 13 Nov 2018 10:14:34 -0800 Subject: [PATCH 3/4] Update doc/src/manual/strings.md Co-Authored-By: lewisl --- doc/src/manual/strings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/manual/strings.md b/doc/src/manual/strings.md index 6ba09bbf1a178..1d8aa4ade6823 100644 --- a/doc/src/manual/strings.md +++ b/doc/src/manual/strings.md @@ -938,7 +938,7 @@ for regular expressions containing quotation marks or newlines). The `Regex()` constructor may be used to create a valid regex string programmatically. This permits using the contents of string variables and other string operations when constructing the regex string. Any of the regex codes above can be used within the single string argument to `Regex()`. Here are some examples: -```julia-repl +```jldoctest julia> using Dates julia> d = Date(1962,7,10) From ca9d2eb907ce66bb8f290ebbcaf75984ac6b8425 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 13 Nov 2018 10:14:59 -0800 Subject: [PATCH 4/4] Update doc/src/manual/strings.md Co-Authored-By: lewisl --- doc/src/manual/strings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/manual/strings.md b/doc/src/manual/strings.md index 1d8aa4ade6823..87a9ed548c636 100644 --- a/doc/src/manual/strings.md +++ b/doc/src/manual/strings.md @@ -947,7 +947,7 @@ julia> d = Date(1962,7,10) julia> regex_d = Regex("Day " * string(day(d))) r"Day 10" -julia> match(regex_d,"It happened on Day 10") +julia> match(regex_d, "It happened on Day 10") RegexMatch("Day 10") julia> name = "Jon"