Extract Script from reverse_construct to construct a regexr Object.

Usage

get_construct(x, file = "", ...)

Arguments

x
A reverse_construct object.
file
A connection, or a character string naming the file to print to. If "" (the default), cat prints to the console unless redirected by sink. Windows users may use file = "clipboard" to copy the content to the clipboard.
...
Other arguments passed to print.reverse_construct.

Extract Script from <code>reverse_construct</code> to <code>construct</code> a <code>regexr</code> Object.

Value

Returns an auto-commented script used to construct a regexr object.

Description

Pulls the reverse_construct attribute from a reverse_construct. This script can be assigned to an object and run in the console to create a comments, named regexr object.

Examples

library("qdapRegex") (myregex <- grab("@rm_time2"))
[1] "(\\d{0,2}:\\d{2}(?:[:.]\\d+)?)(\\s+(([AP]\\.{0,1}M\\.{0,1})|([ap]\\.{0,1}m\\.{0,1})))"
out <- as.regexr(myregex) out
[1] "(\\d{0,2}:\\d{2}(?:[:.]\\d+)?)(\\s+(([AP]\\.{0,1}M\\.{0,1})|([ap]\\.{0,1}m\\.{0,1})))"
summary(out)
(\d{0,2}:\d{2}(?:[:.]\d+)?)(\s+(([AP]\.{0,1}M\.{0,1})|([ap]\.{0,1}m\.{0,1}))) =============================================================================
SUB-EXPR 1: ( NAME : 1 COMMENT : "group and capture to \\1:" SUB-EXPR 2: \d{0,2} NAME : 2 COMMENT : "digits (0-9) (between 0 and 2 times (matching the most amount possible))" SUB-EXPR 3: : NAME : 3 COMMENT : "':'" SUB-EXPR 4: \d{2} NAME : 4 COMMENT : "digits (0-9) (2 times)" SUB-EXPR 5: (?: NAME : 5 COMMENT : "group, but do not capture (optional (matching the most amount possible)):" SUB-EXPR 6: [:.] NAME : 6 COMMENT : "any character of: ':', '.'" SUB-EXPR 7: \d+ NAME : 7 COMMENT : "digits (0-9) (1 or more times (matching the most amount possible))" SUB-EXPR 8: )? NAME : 8 COMMENT : "end of grouping" SUB-EXPR 9: ) NAME : 9 COMMENT : "end of \\1" SUB-EXPR 10: ( NAME : 10 COMMENT : "group and capture to \\2:" SUB-EXPR 11: \s+ NAME : 11 COMMENT : "whitespace (\n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible))" SUB-EXPR 12: ( NAME : 12 COMMENT : "group and capture to \\3:" SUB-EXPR 13: ( NAME : 13 COMMENT : "group and capture to \\4:" SUB-EXPR 14: [AP] NAME : 14 COMMENT : "any character of: 'A', 'P'" SUB-EXPR 15: \.{0,1} NAME : 15 COMMENT : "'.' (between 0 and 1 times (matching the most amount possible))" SUB-EXPR 16: M NAME : 16 COMMENT : "'M'" SUB-EXPR 17: \.{0,1} NAME : 17 COMMENT : "'.' (between 0 and 1 times (matching the most amount possible))" SUB-EXPR 18: ) NAME : 18 COMMENT : "end of \\4" SUB-EXPR 19: | NAME : 19 COMMENT : "OR" SUB-EXPR 20: ( NAME : 20 COMMENT : "group and capture to \\5:" SUB-EXPR 21: [ap] NAME : 21 COMMENT : "any character of: 'a', 'p'" SUB-EXPR 22: \.{0,1} NAME : 22 COMMENT : "'.' (between 0 and 1 times (matching the most amount possible))" SUB-EXPR 23: m NAME : 23 COMMENT : "'m'" SUB-EXPR 24: \.{0,1} NAME : 24 COMMENT : "'.' (between 0 and 1 times (matching the most amount possible))" SUB-EXPR 25: ) NAME : 25 COMMENT : "end of \\5" SUB-EXPR 26: ) NAME : 26 COMMENT : "end of \\3" SUB-EXPR 27: ) NAME : 27 COMMENT : "end of \\2"
comments(out)
$`1` [1] "group and capture to \\\\1:" $`2` [1] "digits (0-9) (between 0 and 2 times (matching the most amount possible))" $`3` [1] "':'" $`4` [1] "digits (0-9) (2 times)" $`5` [1] "group, but do not capture (optional (matching the most amount possible)):" $`6` [1] "any character of: ':', '.'" $`7` [1] "digits (0-9) (1 or more times (matching the most amount possible))" $`8` [1] "end of grouping" $`9` [1] "end of \\\\1" $`10` [1] "group and capture to \\\\2:" $`11` [1] "whitespace (\\n, \\r, \\t, \\f, and \" \") (1 or more times (matching the most amount possible))" $`12` [1] "group and capture to \\\\3:" $`13` [1] "group and capture to \\\\4:" $`14` [1] "any character of: 'A', 'P'" $`15` [1] "'.' (between 0 and 1 times (matching the most amount possible))" $`16` [1] "'M'" $`17` [1] "'.' (between 0 and 1 times (matching the most amount possible))" $`18` [1] "end of \\\\4" $`19` [1] "OR" $`20` [1] "group and capture to \\\\5:" $`21` [1] "any character of: 'a', 'p'" $`22` [1] "'.' (between 0 and 1 times (matching the most amount possible))" $`23` [1] "'m'" $`24` [1] "'.' (between 0 and 1 times (matching the most amount possible))" $`25` [1] "end of \\\\5" $`26` [1] "end of \\\\3" $`27` [1] "end of \\\\2"
subs(out)
$`1` [1] "(" $`2` [1] "\\d{0,2}" $`3` [1] ":" $`4` [1] "\\d{2}" $`5` [1] "(?:" $`6` [1] "[:.]" $`7` [1] "\\d+" $`8` [1] ")?" $`9` [1] ")" $`10` [1] "(" $`11` [1] "\\s+" $`12` [1] "(" $`13` [1] "(" $`14` [1] "[AP]" $`15` [1] "\\.{0,1}" $`16` [1] "M" $`17` [1] "\\.{0,1}" $`18` [1] ")" $`19` [1] "|" $`20` [1] "(" $`21` [1] "[ap]" $`22` [1] "\\.{0,1}" $`23` [1] "m" $`24` [1] "\\.{0,1}" $`25` [1] ")" $`26` [1] ")" $`27` [1] ")"
test(out)
Warning message: The following regex sub-expressions are not valid in isolation: (1) ( (2) (?: (3) )? (4) ) (5) ( (6) ( (7) ( (8) ) (9) ( (10) ) (11) ) (12) )
$regex [1] TRUE $subexpressions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 FALSE TRUE TRUE TRUE FALSE TRUE TRUE FALSE FALSE FALSE TRUE FALSE FALSE TRUE TRUE TRUE TRUE 18 19 20 21 22 23 24 25 26 27 FALSE TRUE FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE
cat(get_construct(out))
construct( `1` = "(" %:)% "group and capture to \\1:", `2` = "\\d{0,2}" %:)% "digits (0-9) (between 0 and 2 times (matching the most amount possible))", `3` = ":" %:)% "':'", `4` = "\\d{2}" %:)% "digits (0-9) (2 times)", `5` = "(?:" %:)% "group, but do not capture (optional (matching the most amount possible)):", `6` = "[:.]" %:)% "any character of: ':', '.'", `7` = "\\d+" %:)% "digits (0-9) (1 or more times (matching the most amount possible))", `8` = ")?" %:)% "end of grouping", `9` = ")" %:)% "end of \\1", `10` = "(" %:)% "group and capture to \\2:", `11` = "\\s+" %:)% "whitespace (\n, \r, \t, \f, and \" \") (1 or more times (matching the most amount possible))", `12` = "(" %:)% "group and capture to \\3:", `13` = "(" %:)% "group and capture to \\4:", `14` = "[AP]" %:)% "any character of: 'A', 'P'", `15` = "\\.{0,1}" %:)% "'.' (between 0 and 1 times (matching the most amount possible))", `16` = "M" %:)% "'M'", `17` = "\\.{0,1}" %:)% "'.' (between 0 and 1 times (matching the most amount possible))", `18` = ")" %:)% "end of \\4", `19` = "|" %:)% "OR", `20` = "(" %:)% "group and capture to \\5:", `21` = "[ap]" %:)% "any character of: 'a', 'p'", `22` = "\\.{0,1}" %:)% "'.' (between 0 and 1 times (matching the most amount possible))", `23` = "m" %:)% "'m'", `24` = "\\.{0,1}" %:)% "'.' (between 0 and 1 times (matching the most amount possible))", `25` = ")" %:)% "end of \\5", `26` = ")" %:)% "end of \\3", `27` = ")" %:)% "end of \\2" )
## On Windows copy to clipboard get_construct(out, file="clipboard")