Questions tagged [replace]

Replacing is the action of searching a string for a sub-string and replacing it with a different string.

Replacing is the action of searching a string (the haystack) for a sub-string (the needle) and replacing it with a different string.

for example, replacing all 'l' within 'Hello' with 'y', would result in 'Heyyo'.

27903 questions
6
votes
2 answers

Remove YAML header from markdown file

How to remove a YAML header like this one from a text file in Ruby: --- date: 2013-02-02 11:22:33 title: "Some Title" Foo: Bar ... --- (The YAML is surrounded by three dashes (-)) I tried text.gsub(/---(.*)---/, '') # text is the variable which…
musicmatze
  • 4,124
  • 7
  • 33
  • 48
6
votes
2 answers

Replacing a querystring parameter value using mod_rewrite

I would like to map this: http://www.example.com/index.php?param1=value1¶m2=value2¶m3=value3 (etc. ad infinitum) to http://www.example.com/index.php?param1=newvalue1¶m2=value2¶m3=value3 (etc.) In other words, just change the value…
Russ
  • 3,768
  • 7
  • 28
  • 37
6
votes
4 answers

JavaScript - Replacing "no-js" class with "js" class not working?

I placed a class in my element called "no-js". This indicates that the user isn't using javascript, (whether it be disabled or blocked). And then, in a script file I created, I want to revoke "no-js" and inject "js" so that I can determine if…
Jace Cotton
  • 2,004
  • 1
  • 21
  • 38
6
votes
3 answers

How to replace the text inside an XML element in R?

I have one input xml file. cat sample.xml <p>ABC </p> R script library(XML) doc = xmlTreeParse("sample.xml", useInternal = TRUE) top<-xmlRoot(doc) sub("<","<",top[[1]]) How can i fix above pblm? Error…
Manish
  • 3,341
  • 15
  • 52
  • 87
6
votes
4 answers

Vim — replace ‘foo’ by ‘bar’ on lines NOT starting with ‘character’

In Vim regular expression, I know it is possible to replace foo by bar on all lines starting with % using :g/^%/s/foo/bar/g but I want to replace foo by bar on all lines NOT starting with %. Is there a way to easily do so?
rberaldo
  • 207
  • 2
  • 8
6
votes
1 answer

Access replacing local table with ODBC linked table preserving original name references

I am trying to replace all the local tables in my Access DB with linked tables from an ODBC data source. I am able to import the new table which comes in as "xyz_table". I want to replace the old local "table" with "xyz_table". However when I…
Baxter
  • 5,633
  • 24
  • 69
  • 105
6
votes
3 answers

Convering double backslash to single backslash in Python 3

I have a string like so: >>> t '\\u0048\\u0065\\u006c\\u006c\\u006f\\u0020\\u20ac\\u0020\\u00b0' That I made using a function that converts unicode to the representative Python escape sequences. Then, when I want to convert it back, I can't get rid…
narnie
  • 1,742
  • 1
  • 18
  • 34
6
votes
2 answers

Getting wildcards to work in find and replace function in VBA macro for Microsoft Word

I have a VBA macro for Microsoft Word that I am trying to improve. The purpose of the macro is to bold and italicize all words in a document that match the search terms in the first table of the document. The problem is the search terms include…
saranicole
  • 2,093
  • 1
  • 23
  • 23
6
votes
3 answers

jQuery replace href value but only partially?

Possible Duplicate: Change href parameter using jQuery I have a page with several links like this: So after PHP page loads it will look like:
Pedro P
  • 373
  • 1
  • 4
  • 16
6
votes
3 answers

Javascript replace contents in string if exists

I have a string that looks like this: var minLength = 3; var mystring = "This field must be {{minLength}} characters" I'm curious of a good way to to detect the presence of {{ ... }} and replace the contents with the minLength variable. As you can…
Fluidbyte
  • 5,162
  • 9
  • 47
  • 76
6
votes
2 answers

Is it possible to switch between + and - using regex in Java?

6*x + 7 = 7*x + 2 - 3*x When we move the right hand side to the left of the equation, we need to flip the operator sign from + to - and vice versa. Using java regex replaceAll, we're able to replace all +'s with -'s. As a result, all the operator…
Terry Li
  • 16,870
  • 30
  • 89
  • 134
6
votes
2 answers

vim visual block search/replace only replacing first occurrence on a line

I'm trying the following command in visual mode to attempt a global find/replace on a block of text :'<,'>s/red/green/g The text looks like this red red red blue red red red blue And the result green red red blue red red red blue Instead of…
darryn.ten
  • 6,784
  • 3
  • 47
  • 65
6
votes
7 answers

Replace every nth letter in a string

I'm writing a function to replace every n-th letter from a string def replaceN(str, n): for i in range(len(str)): n=str[i] newStr=str.replace(n, "*") return newStr but when i execute it, only the first letter is replaced with a…
trek
  • 69
  • 1
  • 1
  • 2
6
votes
4 answers

How can I replace a string in all filenames in a directory? (specifically I need to remove "\#015" from all file names in a directory

Many files in a directory (/root/path/) have a strange character string appended to them (\#015). Help me replace them with regular names without the strange string. I need: /root/path/img1.png\#015 /root/path/img2.jpg /root/path/img3.png\#015 To…
Ryan
  • 14,682
  • 32
  • 106
  • 179
6
votes
2 answers

Replacing dependents with another cell reference in VBA

I've written some VBA code which takes a single cell and identifies all its dependents in the workbook (via a NavigateArrow analysis) and adds their range location to an array. From here I want to be able to update each dependent and change the…