substitution

Replacing Regex matches using lambda expression

佐手、 提交于 2019-11-28 12:51:15
I'm looking for a simple regex find and replace solution were I can just provide a lambda expression for replacing each matches. E.g: regex.MatchReplace(text, match => "replacement string"); This way I can create my own logic for generating the replacement string which may involve invoking various methods etc. i.e. things you can't do with substitution patterns. Anyone know how I can accomplish this? Regex already has one. For ex, string input="abc123def"; var output = Regex.Replace(input, @"\d", m=>(m.Value[0]-'0'+ 5).ToString()); Console.WriteLine(output); OUTPUT: abc678def Please have a

Substitution of characters limited to part of each input line

拜拜、爱过 提交于 2019-11-28 10:49:17
问题 Have a file eg. Inventory.conf with lines like: Int/domain—home.dir=/etc/int I need to replace / and — before the = but not after. Result should be: Int_domain_home_dir=/etc/int I have tried several sed commands but none seem to fit my need. 回答1: Sed with a t loop (BRE): $ sed ':a;s/[-/—.]\(.*=\)/_\1/;ta;' <<< "Int/domain—home.dir=/etc/int" Int_domain_home_dir=/etc/int When one of the -/—. character is found, it's replaced with a _ . Following text up to = is captured and output using

How to get name of variable in R (substitute)?

╄→гoц情女王★ 提交于 2019-11-28 09:13:11
I stacked with trying to pass variable through few functions, and on the final function I want to get the name of the original variable. But it seems like substitute function in R looked only in "local" environment, or just for one level up. Well, let me explain it by code: fun1 <- function (some_variable) {deparse(substitute(some_variable)} fun2 <- function (var_pass) { fun1 (var_pass) } my_var <- c(1,2) # I want to get 'my_var' in the end fun2 (my_var) # > "var_pass" Well, it seems like we printing the name of variable that only pass to the fun1. Documentation of the substitute tells us,

How do I substitute from a list of strings in VIM?

妖精的绣舞 提交于 2019-11-28 08:02:37
问题 I am a vim user, and I want to be able to loop over a range of substrings when I am substituting. How can I use some vim magic to go from a set of lines like this: Afoo Bfoo Cfoo Dfoo to Abar Bbar Cbaz Dbaz ? I want to search my file from the start for the next occurance of foo , and replace the first two instances with bar , and the second two with baz . Is using a for loop the best option? If so, then how do I use the loop variable in the substitution command? 回答1: I would use a function

sed error: “invalid reference \\1 on `s' command's RHS”

做~自己de王妃 提交于 2019-11-28 07:07:09
I run several substitution commands as the core of a colorize script for maven . One of the sed commands uses a regular expression which works find in the shell as discussed here . The current (not working) implementation can be found here . When I include one of the variants of the command into the script different behavior occurs: Variant 1: $ sed -re "s/([a-zA-Z0-9./\\ :-]+)/\1/g" Adapted to the script: -re "s/WARNING: ([a-zA-Z0-9./\\ :-]+)/${warn}WARNING: \1${c_end}/g" \ Error: The shell outputs the same information as if I would type $ sed . Strange!? Variant 2: $ sed -e "s/\([a-zA-Z0-9./

Maven: property substitution not done for /project/version tag of pom?

蓝咒 提交于 2019-11-28 06:56:15
http://maven.apache.org/pom.html#Properties says property "values are accessible anywhere within a POM". Should this read "are accessible in most places within a POM"? I can specify the version of a dependency no problem like so: <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> But what about the version of the project itself like so: <project xmlns="http://maven.apache.org/POM/4.0.0" ...> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>$

How can I substitute the nth occurrence of a match in a Perl regex?

我是研究僧i 提交于 2019-11-28 04:55:27
问题 Following up from an earlier question on extracting the n'th regex match, I now need to substitute the match, if found. I thought that I could define the extraction subroutine and call it in the substitution with the /e modifier. I was obviously wrong (admittedly, I had an XY problem). use strict; use warnings; sub extract_quoted { # à la codaddict my ($string, $index) = @_; while($string =~ /'(.*?)'/g) { $index--; return $1 if(! $index); } return; } my $string = "'How can I','use' 'PERL','to

Why aren't my XSLT variables substituting their values?

不羁岁月 提交于 2019-11-28 04:10:41
问题 I am trying to use XSLT variables and not having much success, hopefully I'm just doing something dumb. I have the following code snippet: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" version="1.0"> <xsl:template match="/"> <xsl:variable name="config" select="query/@config"></xsl:variable> so I expect there to be a variable 'config' set to the value of the 'config' attribute of my top-level element 'query'. I then try to use the

How to use a variable as modifier in a substitution

≯℡__Kan透↙ 提交于 2019-11-28 02:01:30
Is there a way to use a variable as modifier in a substitution? my $search = 'looking'; my $replace = '"find: $1 ="'; my $modifier = 'ee'; s/$search/$replace/$modifier; I need to use an array of hashes to make bulk search-replace with different modifiers. Hm, if I had to do it I would do like this: use warnings; use strict; my @stuff = ( { search => "this", replace => "that", modifier => "g", }, { search => "ono", replace => "wendy", modifier => "i", } ); $_ = "this ono boo this\n"; for my $h (@stuff) { if ($h->{modifier} eq 'g') { s/$h->{search}/$h->{replace}/g; } elsif ($h->{modifier} eq 'i'

How to use ASP.Net server controls inside of Substitution control?

无人久伴 提交于 2019-11-28 01:14:13
问题 while the method we use in Substitution control should return strings, so how is it possible to use a donut caching in web forms on a server control which should be rendered server side? for example Loginview control? 回答1: UPDATE This is now a fully working example. There a few things happening here: Use the call back of a substitution control to render the output of the usercontrol you need. Use a custom page class that overrides the VerifyRenderingInServerForm and EnableEventValidation to