{"id":6138,"date":"2022-12-20T18:57:57","date_gmt":"2022-12-20T21:57:57","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/regsub-mann\/"},"modified":"2022-12-20T18:57:57","modified_gmt":"2022-12-20T21:57:57","slug":"regsub-mann","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/regsub-mann\/","title":{"rendered":"regsub (mann)"},"content":{"rendered":"<h1 align=\"center\">regsub<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#KEYWORDS\">KEYWORDS<\/a> <\/p>\n<hr>\n<p>______________________________________________________________________________<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">regsub \u2212 Perform substitutions based on regular expression pattern matching<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>regsub<\/b> ?<i>switches<\/i>? <i>exp string subSpec<\/i> ?<i>varName<\/i>? ______________________________________________________________________________<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This command matches the regular expression <i>exp<\/i> against <i>string<\/i>, and either copies <i>string<\/i> to the variable whose name is given by <i>varName<\/i> or returns <i>string<\/i> if <i>varName<\/i> is not present. (Regular expression matching is described in the <b>re_syntax<\/b> reference page.) If there is a match, then while copying <i>string<\/i> to <i>varName<\/i> (or to the result of this command if <i>varName<\/i> is not present) the portion of <i>string<\/i> that matched <i>exp<\/i> is replaced with <i>subSpec<\/i>. If <i>subSpec<\/i> contains a \u201c&#038;\u201d or \u201c\u0000\u201d, then it is replaced in the substitution with the portion of <i>string<\/i> that matched <i>exp<\/i>. If <i>subSpec<\/i> contains a \u201c<i>n<\/i>\u201d, where <i>n<\/i> is a digit between 1 and 9, then it is replaced in the substitution with the portion of <i>string<\/i> that matched the <i>n<\/i>\u2019th parenthesized subexpression of <i>exp<\/i>. Additional backslashes may be used in <i>subSpec<\/i> to prevent special interpretation of \u201c&#038;\u201d, \u201c\u0000\u201d, \u201c<i>n<\/i>\u201d and backslashes. The use of backslashes in <i>subSpec<\/i> tends to interact badly with the Tcl parser\u2019s use of backslashes, so it is generally safest to enclose <i>subSpec<\/i> in braces if it includes backslashes.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If the initial arguments to <b>regsub<\/b> start with <b>\u2212<\/b> then they are treated as switches. The following switches are currently supported:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"6%\">\n<p><b>\u2212all<\/b><\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"78%\">\n<p>All ranges in <i>string<\/i> that match <i>exp<\/i> are found and substitution is performed for each of these ranges. Without this switch only the first matching range is found and substituted. If <b>\u2212all<\/b> is specified, then \u201c&#038;\u201d and \u201c<i>n<\/i>\u201d sequences are handled for each substitution using the information from the corresponding match.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>\u2212expanded<\/b><\/p>\n<p style=\"margin-left:22%;\">Enables use of the expanded regular expression syntax where whitespace and comments are ignored. This is the same as specifying the <b>(?x)<\/b> embedded option (see the <b>re_syntax<\/b> manual page).<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p><b>\u2212line<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"78%\">\n<p>Enables newline-sensitive matching. By default, newline is a completely ordinary character with no special meaning. With this flag, \u201c[^\u201d bracket expressions and \u201c.\u201d never match newline, \u201c^\u201d matches an empty string after any newline in addition to its normal function, and \u201c$\u201d matches an empty string before any newline in addition to its normal function. This flag is equivalent to specifying both <b>\u2212linestop<\/b> and <b>\u2212lineanchor<\/b>, or the <b>(?n)<\/b> embedded option (see the <b>re_syntax<\/b> manual page).<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>\u2212linestop<\/b><\/p>\n<p style=\"margin-left:22%;\">Changes the behavior of \u201c[^\u201d bracket expressions and \u201c.\u201d so that they stop at newlines. This is the same as specifying the <b>(?p)<\/b> embedded option (see the <b>re_syntax<\/b> manual page).<\/p>\n<p style=\"margin-left:11%;\"><b>\u2212lineanchor<\/b><\/p>\n<p style=\"margin-left:22%;\">Changes the behavior of \u201c^\u201d and \u201c$\u201d (the \u201canchors\u201d) so they match the beginning and end of a line respectively. This is the same as specifying the <b>(?w)<\/b> embedded option (see the <b>re_syntax<\/b> manual page).<\/p>\n<p style=\"margin-left:11%;\"><b>\u2212nocase<\/b><\/p>\n<p style=\"margin-left:22%;\">Upper-case characters in <i>string<\/i> will be converted to lower-case before matching against <i>exp<\/i>; however, substitutions specified by <i>subSpec<\/i> use the original unconverted form of <i>string<\/i>.<\/p>\n<p style=\"margin-left:11%;\"><b>\u2212start<\/b> <i>index<\/i><\/p>\n<p style=\"margin-left:22%;\">Specifies a character index offset into the string to start matching the regular expression at. The <i>index<\/i> value is interpreted in the same manner as the <i>index<\/i> argument to <b>string index<\/b>. When using this switch, \u201c^\u201d will not match the beginning of the line, and A will still match the start of the string at <i>index<\/i>. <i>index<\/i> will be constrained to the bounds of the input string.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"3%\">\n<p><b>\u2212\u2212<\/b><\/p>\n<\/td>\n<td width=\"8%\"><\/td>\n<td width=\"78%\">\n<p>Marks the end of switches. The argument following this one will be treated as <i>exp<\/i> even if it starts with a <b>\u2212<\/b>.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>varName<\/i> is supplied, the command returns a count of the number of matching ranges that were found and replaced, otherwise the string after replacement is returned. See the manual entry for <b>regexp<\/b> for details on the interpretation of regular expressions.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Replace (in the string in variable <i>string<\/i>) every instance of <b>foo<\/b> which is a word by itself with <b>bar<\/b>:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>regsub<\/b> -all {mfooM} $string bar string<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">or (using the \u201cbasic regular expression\u201d syntax):<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>regsub<\/b> -all {(?b)<foo>} $string bar string<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Insert double-quotes around the first instance of the word <b>interesting<\/b>, however it is capitalized.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>regsub<\/b> -nocase {yinterestingy} $string {&#8220;&#038;&#8221;} string<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Convert all non-ASCII and Tcl-significant characters into u escape sequences by using <b>regsub<\/b> and <b>subst<\/b> in combination:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"># This RE is just a character class for almost everything &#8220;bad&#8221; <br \/> set RE {[][{};#\\$ rtu0080-uffff]}<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"># We will substitute with a fragment of Tcl script in brackets <br \/> set substitution {[format \\\\u%04x [scan &#8220;\\&#038;&#8221; %c]]}<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"># Now we apply the substitution to get a subst-string that <br \/> # will perform the computational parts of the conversion. Note <br \/> # that newline is handled specially through <b>string map<\/b> since <br \/> # backslash-newline is a special sequence. <br \/> set quoted [subst [string map {n {\\u000a}}  <br \/> [<b>regsub<\/b> -all $RE $string $substitution]]]<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">regexp(n), re_syntax(n), subst(n), string(n)<\/p>\n<h2>KEYWORDS <a name=\"KEYWORDS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">match, pattern, quoting, regular expression, substitution<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  regsub \u2212 Perform substitutions based on regular expression pattern matching <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3783,1],"tags":[2635,2792],"class_list":["post-6138","post","type-post","status-publish","format-standard","hentry","category-n-comandos-tcl-tk","category-sin-categoria","tag-mann","tag-regsub"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6138"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6138\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}