Questions tagged [substitution]

The action of replacing something with another thing.

The action of replacing something with another thing.

1879 questions
10
votes
1 answer

Sphinx variable substitution in code blocks

Using Sphinx 1.2.3 and given this RST snippet: .. code-block:: xml |version| and in conf.py I have: version = '1.0.2' How do you ensure that the above RST snippet renders as:
Les Hazlewood
  • 18,480
  • 13
  • 68
  • 76
10
votes
2 answers

Lua: Substitute list of characters in string

Is it possible to substitute characters according to a list in Lua, like tr in Perl? For example, I would like to substitute A to B and B to A (e.g. AABBCC becomes BBAACC). In Perl, the solution would be $str ~= tr/AB/BA/. Is there any native way of…
Fábio Perez
  • 23,850
  • 22
  • 76
  • 100
9
votes
2 answers

Simultaneous substitutions with s/// in Perl 6

Is there a way to do simultaneous substitutions with s///? For instance, if I have a string with a number of 1s, 2s, 3s, etc, and I want to substitute 1 with "tom", and 2 with "mary", and 3, with "jane", etc? my $a = "13231313231313231"; say $a ~~…
lisprogtor
  • 5,677
  • 11
  • 17
9
votes
8 answers

Formula to eliminate all but alpha characters

I need to scrub a column of names in Excel to eliminate all non-Alpha characters including periods, commas, spaces, hyphens and apostrophes. EXAMPLE: Change O'Malley-Smith, Tom, Jr. to OMALLEYSMITHTOMJR The client requires this to be an Excel…
dwwilson66
  • 6,806
  • 27
  • 72
  • 117
9
votes
3 answers

awk substitute shell variables

I am struggling with awk substitution, for some reason the following code does not substitute anything, it just prints the output unaltered. Can anyone see what I am missing here? Any help would be very much appreachiated! (PS! The $DOCPATH and…
Dan-Simon Myrland
  • 327
  • 1
  • 5
  • 10
9
votes
1 answer

match.call called in wrong environment when eval’ing

I tried implementing a function let with the following semantics: > let(x = 1, y = 2, x + y) [1] 3 … which is conceptually somewhat similar to substitute with the syntax of with. The following code almost works (the above invocation for instance…
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
9
votes
1 answer

What causes substitution in Vim to only match one element per line?

I've been making a lot of changes to my .vimrc lately, and somewhere along the line I've introduced an undesirable feature. When performing a substitution command where the search token appears more than once per line, only the first token is…
chpatton013
  • 363
  • 1
  • 5
  • 11
8
votes
7 answers

Substitution with sed + bash function

my question seems to be general, but i can't find any answers. In sed command, how can you replace the substitution pattern by a value returned by a simple bash function. For instance, I created the following function : function parseDates(){ …
Samir Boulil
  • 83
  • 1
  • 1
  • 3
8
votes
3 answers

Can I use variable substitution with ansible-galaxy and requirements.yml?

We have private git repos for a number of Ansible roles. The repo hosts vary from site to site, for example: Site1 uses https://gitforsite1.ourdomain.com Site2 uses https://gitforsite2.ourdomain.com What I want is to have a single…
ChalkBoard
  • 101
  • 1
  • 5
8
votes
1 answer

Substitute substrings using a dictionary in Python

I have this string message = '10100010011' and this dictionary codes = {97: '1', 98: '01', 107: '001', 114: '000'} and I need to substitute the original message using the dictionary to something like this [97, 98, 114, 97, 107, 97] I tried my…
Arcane
  • 669
  • 1
  • 10
  • 25
8
votes
1 answer

Vim what is the use of exclamation mark in substitute command

I recently found a substitute command for vim where the author had the / replaced by a ! like this: :%s!foo!bar and I don't understand the difference with the traditionnal :%s/foo/bar. I searched some documentation on this syntax but I didn't find…
statox
  • 2,827
  • 1
  • 21
  • 41
8
votes
1 answer

Search and replace across multiple lines with conversion to lower case in Vim

Here's what I'd like to do, for each one of many files: search for all occurrences of convert the entire match to lowercase
Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
8
votes
6 answers

Best way to substitute variables in plain text using PHP

What's the best way to take some plain text (not PHP code) which contains PHP-style variables, and then substitute in the value of the variable. This is kinda hard to describe, so here's an example. // -- myFile.txt -- Mary had a little $pet. // --…
nickf
  • 537,072
  • 198
  • 649
  • 721
8
votes
2 answers

Replacing named capturing groups with re.sub

I want to replace the text of matched re patterns in a string and can do this using re.sub(). If I pass it a function as the repl argument in the call it works as desired, as illustrated below: from __future__ import print_function import…
martineau
  • 119,623
  • 25
  • 170
  • 301
8
votes
2 answers

Non standard evaluation in Hadley's advanced R book

In Hadley's Advanced R book, there is a piece of code that I cannot understand the output. f <- function(x) substitute(x) g <- function(x) deparse(f(x)) g(1:10) g(x) g(x + y ^ 2 / z + exp(a * sin(b))) Why do they all return "x"? Especially when g…
Heisenberg
  • 8,386
  • 12
  • 53
  • 102