Questions tagged [regsub]

regsub is a command that matches the regular expression exp against string in TCL.

This command matches the regular expression exp against string, and either copies string to the variable whose name is given by varName or returns string if varName is not present. (Regular expression matching is described in the re_syntax reference page.) If there is a match, then while copying string to varName (or to the result of this command if varName is not present) the portion of string that matched exp is replaced with subSpec. If subSpec contains a “&” or “\0”, then it is replaced in the substitution with the portion of string that matched exp. If subSpec contains a “\n”, where n is a digit between 1 and 9, then it is replaced in the substitution with the portion of string that matched the n'th parenthesized subexpression of exp. Additional backslashes may be used in subSpec to prevent special interpretation of “&”, “\0”, “\n” and backslashes. The use of backslashes in subSpec tends to interact badly with the Tcl parser's use of backslashes, so it is generally safest to enclose subSpec in braces if it includes backslashes. If the initial arguments to regsub start with - then they are treated as switches.

Read more: http://www.tcl.tk/man/tcl/TclCmd/regsub.htm

27 questions
2
votes
1 answer

TCL regsub to variable?

I'm setting up macros, Set, and Say. Defined in procedures. proc Set {key value args} { set ::$key $value set "::key2" "$key" } proc Say {key} { puts $key } proc Say2 {key} { set key3 [regsub "\%" $key "\$"] puts $key3 eval puts…
Mookie
  • 43
  • 5
2
votes
2 answers

Using R how to separate a string based on characters

I have a set of strings and I need to search by words that have a period in the middle. Some of the strings are concatenated so I need to break them apart in to words so that I can then filter for words with dots. Below is a sample of what I have…
user3357059
  • 1,122
  • 1
  • 15
  • 30
1
vote
6 answers

Removing tabs from a string using either sed or awk and tcl regsub function

Say I have a string as name = xyz here after name there is a tab and after '=' there are random number of spaces. I need an output as name=xyz So how can I remove both tabs and random number of spaces from the above mentioned string using sed or…
1
vote
1 answer

TCL regsub uses RegEx match as index in associate array

I'd like to automatically convert URLs, i.e "https://sc-uat.ct.example.com/sc/" into "https://invbeta.example.com/sc/" "https://sc-dev.ct.example.com/sc/" into "https://invtest.example.com/sc/" "https://sc-qa.ct.example.com/sc/" into…
Sam D.
  • 265
  • 2
  • 10
1
vote
3 answers

Remove elements with dot extension from list using regex or string matching

I'm newbie to Tcl. I have a list like this: set list1 { dir1 fil.txt dir2 file.xls arun baskar.tcl perl.pl } From that list I want only elements like: dir1 dir2 arun I have tried the regexp and lsearch but no…
Samuel E
  • 13
  • 5
1
vote
1 answer

Replacing a specific part

I have a list like this: DEL075MD1BWP30P140LVT AN2D4BWP30P140LVT INVD0P7BWP40P140 IND2D6BWP30P140LVT I want to replace everything in between D and BWP with a * How can I do that in unix and tcl
1
vote
2 answers

Regexp to match specific characters in tcl

I have a variable that contains following characters "@/$%&*#{}4g_.[]3435_.technology@lte042" I want to match only "4g_.3435_.technologylte042" by excluding special characters Code: set a "@\/$%&*#[](){}4g_.[]3435_.technology@lte042" regexp…
gpk
  • 13
  • 1
  • 4
1
vote
2 answers

capture value to the left of querystring using regsub

Here is a sample URL: https://mydomainname.net/productimages/1679/T716AP1_lg.jpg?w=125&h=125&tstamp=05/19/2016%2015:08:30 What I want from this is just: /productimages/1679/T716AP1_lg My current code is: regsub(req.url, "^/(.*)\.(.*)$",…
Slee
  • 27,498
  • 52
  • 145
  • 243
0
votes
1 answer

Regsubbing simple matches

I'm looking for a regsub example that does the following: 123tcl456TCL789 => 123!tcl!456!TCL!789 This is an Tcl example => This is an !Tcl! example Yes, I could use string first to find a position and mash things but I saw in past a regsub command…
0
votes
0 answers

Regsubsets not displaying variables selected

I have to perform forward subset selection on College data for the ISLR package, modelling one variable against the others on a training set. Normally I should have a list of variables like Subset selection object Call: regsubsets.formula(Outstate ~…
therickster
  • 111
  • 6
0
votes
1 answer

Tcl string compare and replace with asterisk

I want to compare two strings in TCL and replace the unmatched character with asterisk. Core_cpuss_5/loop2/hex_reg[89]cpu_ip[45]_reg10/D[23] Core_cpuss_5/loop2/hex_reg[56]cpu_ip[12]_reg5/D[33] Output Required : Core_cpuss_5/loop2/hex_reg[ * ]cpu_ip[…
gstekboy
  • 1
  • 1
0
votes
1 answer

Varnish regular expression regsuball to uppercase (support Replacement Text Case Conversion)

I am looking for proper handling of URLs in Varnish (5.2.1), here is what I do (trying to redirect to lowercase URLs): set req.url = std.tolower(req.url); //this is new.url //if original.url != new.url => redirect This produce good URL, until…
2ge
  • 269
  • 4
  • 12
0
votes
1 answer

find and replace a number inside a file in tcl

I have a huge file. I need to find the line containing the pattern abc_x and replace its value 0.34 to 10% increased value. And then copy the entire file (with replaced values) into a new file. I am new to Tcl, please let me know how to do…
sing20
  • 11
  • 2
0
votes
2 answers

How to make without exception uppercase and lowercase letters in tcl regsub?

I want to regsub without exception, so as not to double I do a regsub. example before: regsub -all "feat" $songtitle "" songtitle regsub -all "Feat" $songtitle "" songtitle I want a simple one line for regsub: regsub -all "feat" $songtitle ""…
gUfriL
  • 135
  • 1
  • 7
0
votes
1 answer

How to set \n to a str in tcl

Hi I am new to tcl and want to assign "\n" to a variable and use that variable in regsub to replace that string. It should be like : set a "\n\[\"this is my code\"\]" puts $a I was expecting this will give \n\[\"this is my code\"\], then I could…
Shang
  • 17
  • 3
1
2