How to replace with white space in tcl - replace

I am trying replace the with whitespace like
string map [list " "]. but it is not replacing it.How could we acheive it in tcl script.

String map expects a key-value pair list as the first argument. The key is what it should search for and the value is what to replace with. So what you want is:
string map { " "} $input

Related

How to exclude string enclosed in braces {xxx} and empty string using regular expression?

I have a list of string, now I want to filter out the strings look like this: {xxxx} and empty strings: "", " ", " " ...
Please advice.
Is this working for you:
^(?:\s*|\{[^}]*\})$
This regex matches strings that contain 0 or more spaces or something between opening and closing curlybraces.

Scala regex match and split

So here's what I want to do:
input string: "abc From: blah"
I want to split this so that the result is
["abc" "From: blah"] or ["abc" "From" "blah"
I have several other patterns to match
["abcd" "To:" "blah"] etc
So I have the following regex
val datePattern = """((.*>.*)|(.*(On).*(wrote:)$)|(.*(Date):.*(\+\d\d\d\d)?$)|(.*(From):.*(\.com)?(\]|>)?$))"""
val reg = datePattern.r
If I do a match the result comes out fine.
If I do a split on the same regex I get an empty list.
inputStr match {
case reg(_*) => return "Match"
case _ => return "Output: None"
}
on the input string :
"abc From: blah blah"
returns Match
Split
inputStr.split(datePattern)
returns an empty array. What am I possibly missing ?
Since the regexp matches the string, split will remove the entire string (considered as a separator).
The default behavior is not to return two empty strings, but an empty array in this case, as given by the split signification.
https://stackoverflow.com/a/14602089/1287856
Concerning why your regex matches in its entirety, you might find this website useful (it concerns your example directly)
https://regex101.com/r/zY0lX9/1
Split finds the whole regexp and removes all its occurences from the string, returning the interleaved strings as an array. You may want to split on something like "(?=From:)" so that it does not remove anything.

Match any char inside two quotation pairs, including nested quotations

I have data that will appear as dual quotation pairs like this, per line.
"Key" "Value"
Inside of these pairs there can be any character, and sometimes there comes the
dreaded "" nested pair:
"Key "superkey"" ""Space" Value"
Previously I've found: "([^"]*)"\s*"([^"]*)"
And this matches Key and Value to two groups:
$1 = Key
$2 = Value
But, with the nested pairs, it will only output:
$1 = superkey
Is there a way to match all characters between the pairs? Example output wanted:
$1 = Key "superkey"
$2 = "Space" Value
Regular expression processing from QRegularExpression and c++11 Literal string:
QRegularExpression(R"D("([^"]*)"\s*"([^"]*)")D");
I know it matches Pearl and PHP regex.
"(.*?)"[\t\r ]+"(.*?)"(?=[ ]*$)
Try this.See demo.
https://regex101.com/r/hR7tH4/2

How can i remove a substring using regexp in Perl?

Given a file containing multiple strings (one in each line) - among them there will be the following two strings:
de12_QA_IR_OS_HV
de12_IR_OS_HV
(the only difference is "QA_" in the right position).
I need to perform some action if the current line being handled contains one of the above.
if yes, i should use the string value without the "QA_" substring.
I am using the following regexp to detect the values /de12_(QA_)?IR_OS_HV/ but is there a way to remove the "QA_" if it exist using the same regexp ?
You can capture what's before and after the QA_:
if (/(de12_)(QA_)?(IR_OS_HV)/) {
print $1 . $3, "\n";
Or, use substitution
if (s/de12_(QA_)?IR_OS_HV/de12_IR_OS_HV/) {
print $_, "\n";
}
But, in fact, you know what string to use if you the regex matches:
if (/de12_(QA_)?IR_OS_HV/) {
print "de12_IR_OS_HV\n";
}

Insert space in string using powershell?

I have a number of files, each with a number of lines of plain text in them and I'd like to insert a space between certain "words".
I have no problem looping the files, or replacing some text with different text, but not sure how to keep the existing text when I do so!
$ln = "20142301 Starting_LOC1SVR14"
$newln = $ln -replace "_", " "
$newln = $newln -replace "LOC[0-9]","????"
Given this sample, I want to insert the space between LOC1 and SVR14 to give LOC1 SVR14
Note that the LOC goes up to 16, but I can write the regex for 1 or more numerals, it's keeping that LOC1 part thats giving me the headache!
Look up regexp capture groups. They are used to save the matching string into a variable that can be used later like so,
$newln -replace "LOC[0-9]+","$0 " # $0 is the match, so replace the match with "match "
20142301 Starting LOC1 SVR14