tagged [replace]

regex string replace

regex string replace I am trying to do a basic string replace using a regex expression, but the answers I have found do not seem to help - they are directly answering each persons unique requirement w...

4 May at 08:59

How to replace an entire line in a text file by line number

How to replace an entire line in a text file by line number I have a situation where I want a bash script to replace an entire line in a file. The line number is always the same, so that can be a hard...

19 Apr at 21:54

Replace spaces with dashes and make all letters lower-case

Replace spaces with dashes and make all letters lower-case I need to reformat a string using jQuery or vanilla JavaScript Let’s say we have `"Sonic Free Games"`. I want to convert it to `"sonic-free-g...

2 Mar at 13:35

Replace CRLF using powershell

Replace CRLF using powershell Here is my powershell script: ``` $original_file ='C:\Users\abc\Desktop\File\abc.txt' (Get-Content $original_file) | Foreach-Object { $_ -replace "'", "2"` -replace '2', ...

22 Feb at 04:19

Alternative to String.Replace

Alternative to String.Replace So I was writing some code today that basically looks like this: ``` string returnString = s.Replace("!", " ") .Replace("@", " ") .Replace("#", " ") .Re...

16 Dec at 23:29

How to replace multiple substrings of a string?

How to replace multiple substrings of a string? I would like to use the .replace function to replace multiple strings. I currently have but would like to have something like although that does not fe...

8 Dec at 16:57

Can I replace groups in Java regex?

Can I replace groups in Java regex? I have this code, and I want to know, if I can replace only groups (not all pattern) in Java regex. Code: ``` //... Pattern p = Pattern.compile("(\\d).*(\\d)"); S...

21 Nov at 06:45

Replacing escape characters from JSON

Replacing escape characters from JSON I want to replace the "\" character from a JSON string by a empty space. How can I do that?

2 Nov at 06:37

How to Replace by pattern with Regex in C#

How to Replace by pattern with Regex in C# I have a text, the text contains char sequence which begins with # and ends with ="" characters. Between the # and ="" characters just exists alphanumeric ch...

24 Oct at 07:20

Regex : how to get words from a string (C#)

Regex : how to get words from a string (C#) My input consists of user-posted strings. What I want to do is create a dictionary with words, and how often they’ve been used. This means I want to parse a...

11 Oct at 19:42

Replace all values in a matrix <0.1 with 0

Replace all values in a matrix

19 Sep at 08:10

Is it more or less efficient to perform a check before performing a Replace in C#?

Is it more or less efficient to perform a check before performing a Replace in C#? This is an almost academic question but I'm curious as to its answer. Suppose you have a loop that performs a routine...

10 Sep at 06:43

Mongodb implications of update versus replace

Mongodb implications of update versus replace I have read [this related question](https://stackoverflow.com/q/35848688/304832), but the one below is different. The mongodb c# driver has a `ReplaceOne`...

5 Sep at 19:11

Java how to replace 2 or more spaces with single space in string and delete leading and trailing spaces

Java how to replace 2 or more spaces with single space in string and delete leading and trailing spaces Looking for quick, simple way in Java to change this string to something that looks like this wh...

4 Sep at 05:0

C# Trim() vs replace()

C# Trim() vs replace() In a C# `string` if we want to replace `" "` in a string to `string.empty`, is it fine to use `stringValue.Trim()` or `stringValue.replace(" ", string.empty)`. Both serve the sa...

14 Aug at 16:7

Is there an alternative to string.Replace that is case-insensitive?

Is there an alternative to string.Replace that is case-insensitive? I need to search a string and replace all occurrences of `%FirstName%` and `%PolicyAmount%` with a value pulled from a database. The...

9 Aug at 03:53

How to replace a character from a String in SQL?

How to replace a character from a String in SQL? I have 100's of cells in our database which contain `?` instead of `'`. It is possible that this might happen in all rows and columns and in more than ...

3 Aug at 20:31

JS. How to replace html element with another element/text, represented in string?

JS. How to replace html element with another element/text, represented in string? I have a problem with replacing html elements. For example, here is a table: (it can be div, span, anything) And strin...

7 Jun at 19:18

Replace any string between quotes

Replace any string between quotes Cannot find a consistent way to replace a random string between quotes with a specific string I want. Any help would be greatly appreciated. should become but also wo...

23 May at 12:24

Regular expression that matches all valid format IPv6 addresses

Regular expression that matches all valid format IPv6 addresses [Regular expression that matches valid IPv6 addresses](https://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-i...

23 May at 12:2

Replacing multiple characters in a string, the fastest way?

Replacing multiple characters in a string, the fastest way? I am importing some number of records with multiple `string` fields from an old db to a new db. It seems to be very slow and I suspect it's ...

23 May at 12:1

Configurable sensitive data masking via log4net

Configurable sensitive data masking via log4net I'm looking at using log4net as my logging framework of choice for a new project starting shortly. One issue that I've run into during prototyping that ...

23 May at 11:33

Remove all multiple spaces in Javascript and replace with single space

Remove all multiple spaces in Javascript and replace with single space How can I automatically replace all instances of multiple spaces, with a single space, in Javascript? I've tried chaining some `s...

20 May at 17:25

JavaScript: replace last occurrence of text in a string

JavaScript: replace last occurrence of text in a string See my code snippet below: ``` var list = ['one', 'two', 'three', 'four']; var str = 'one two, one three, one four, one'; for ( var i = 0; i

25 Apr at 17:4

Alternative to multiple String.Replaces

Alternative to multiple String.Replaces My code uses `String.Replace` several times in a row: I suspect there's a better and faster way to do it. What would you suggest?

30 Mar at 15:22

MySQL search and replace some text in a field

MySQL search and replace some text in a field What MySQL query will do a text search and replace in one particular field in a table? I.e. search for `foo` and replace with `bar` so a record with a fie...

1 Dec at 20:41

php Replacing multiple spaces with a single space

php Replacing multiple spaces with a single space I'm trying to replace multiple spaces with a single space. When I use `ereg_replace`, I get an error about it being deprecated. Is there an identical ...

MySQL string replace

MySQL string replace I have a column containing urls (id, url): I'd like to change the word "updates" to "news". Is it possible to do this with a scrip

17 Aug at 22:48

Simple excel find and replace for formulas

Simple excel find and replace for formulas I have numerous cells all over the place on a worksheet that look like `=((E9-E8)/E8)`. I want to use the first two values to go into this new formula, `(EXP...

21 Jun at 06:28

Replace substring with another substring C++

Replace substring with another substring C++ How could I replace a substring in a string with another substring in C++, what functions could I use?

1 Jun at 14:45

Regular expression search replace in Sublime Text 2

Regular expression search replace in Sublime Text 2 I'm looking to do search replace with regular expressions in Sublime Text 2. The [documentation on this](http://docs.sublimetext.info/en/latest/sear...

25 May at 15:33

how to use a regular expression to extract json fields?

how to use a regular expression to extract json fields? Beginner RegExp question. I have lines of JSON in a textfile, each with slightly different Fields, but there are 3 fields I want to extract for ...

13 May at 13:3

Using tr to replace newline with space

Using tr to replace newline with space Have output from `sed`: Those two strings should be merged into one and separated with space like: Two strings are pipelined to `tr` in order to replace newline ...

7 Mar at 01:53

How to find and replace with regex in excel

How to find and replace with regex in excel I have an excel file with 1 column and multiple rows. The rows contain various text, here's an example: I want to replace "texts are *" where * is anything ...

15 Jan at 20:45

What would be the fastest way to remove Newlines from a String in C#?

What would be the fastest way to remove Newlines from a String in C#? I have a string that has some Environment.Newline in it. I'd like to strip those from the string and instead, replace the Newline ...

20 Nov at 11:39

UPDATE and REPLACE part of a string

UPDATE and REPLACE part of a string I've got a table with two columns, `ID` and `Value`. I want to change a part of some strings in the second column. Example of Table: Now the `123\` in the `Valu

C# Replacing part of string by start and end position

C# Replacing part of string by start and end position I have a string and I want to replace a part of it. The tricky part is that that I can't use Regex.replace, because I only know the start and end ...

4 Sep at 20:9

Replace single backslash with double backslash

Replace single backslash with double backslash It seems simple enough, right? Well, I don't know. Here's the code I'm trying: However, I'm receiving an error, > ArgumentException was unhandled - parsi...

14 Jul at 21:38

Replace "\\" with "\" in a string in C#

Replace "\\" with "\" in a string in C# I still don't get how to do this. I saw many posts regarding this, but none of the solutions worked for me. I have a string called "a\\b". The result I need is ...

14 Jul at 21:36

How to use operator '-replace' in PowerShell to replace strings of texts with special characters and replace successfully

How to use operator '-replace' in PowerShell to replace strings of texts with special characters and replace successfully I have a script where I am basically doing a find and replace on several strin...

13 Jul at 13:41

Find and replace words/lines in a file

Find and replace words/lines in a file I have a file (more specifically, a log4j configuration file) and I want to be able to read in the file and pick out certain lines in the code and replace them. ...

16 Jun at 02:3

How to replace specific values in a oracle database column?

How to replace specific values in a oracle database column? I am looking to replace values in a particular column. For example the following column values should be (replacing `est1` with `rest1`)

12 Jun at 14:27

Removing double quotes from a string in Java

Removing double quotes from a string in Java How would I remove double quotes from a String? For example: I would expect `"abd` to produce `abd`, without the double quote. Here's the code I've tried:

2 May at 17:26

Replace a character at a specific index in a string?

Replace a character at a specific index in a string? I'm trying to replace a character at a specific index in a string. What I'm doing is: This gives an error. Is there any method to do this?

How to replace space with comma using sed?

How to replace space with comma using sed? I would like to replace the empty space between each and every field with comma delimiter.Could someone let me know how can I do this.I tried the below comma...

24 Jun at 05:59

Remove multiple whitespaces

Remove multiple whitespaces I'm getting `$row['message']` from a MySQL database and I need to remove all whitespace like `\n` `\t` and so on. should be formatted to: I tried: b

How to delete all instances of a character in a string in python?

How to delete all instances of a character in a string in python? How do I delete all the instances of a character in this string? Here is my code: However, if I run this, this is what happens: ``` >>...

5 Mar at 02:23

C# hexadecimal value 0x12, is an invalid character

C# hexadecimal value 0x12, is an invalid character I am loading a lot of xml documents and some of them return errors like "hexadecimal value 0x12, is an invalid character" and there are different cha...

10 Jan at 19:46

PHP preg replace only allow numbers

PHP preg replace only allow numbers How can I modify this existing preg_replace to only allow numbers?

9 Jan at 16:54

How to remove spaces and newlines in a string

How to remove spaces and newlines in a string sorry if they are not very practical for C # Asp.Net, I hope to make me understand I have this situation I would make sure that the string does not contai...

9 Jan at 10:19