replace

Find and Replace a section of a string with wildcard type search using RegEx (while retaining some text)

I am trying to replace some text in a string with different text while retaining some of the text and I am having trouble doing it. My code is: StreamReader reader = new StreamReader(fDialog.FileName.ToString()); string content = reader.ReadToEnd(); reader.Close(); /Replace M2 with M3 (this works fine) content = Regex.Replace(conten...

jQuery - want to get input value for submit but it gets one and repeats

I'm trying to replace all submit buttons with a span so cufon will work. The input still needs to be there so have done some css to hide it and overlay to span on top. My issue is getting the value from the input tag is proving quite diffcult. The code below gets the first input value (being 'search' from the search box at the top of ...

How do I replace an actual asterisk character (*) in a Regex expression?

I have a statement: I have a string such as content = "* test *" I want to search and replace it with so when I am done the string contains this: content = "(*) test (*)" My code is: content = Regex.Replace(content, "*", "(*)"); But this causes an error in C# because it thinks that the * is part of the Regular Express...

Replacing strings with regex in JavaScript

A particular regular expression is bugging me right now. I simply want to replace the range=100 in a string like var string = '...commonstringblabla<b>&range=100&</b>stringandsoon...'; with ...commonstringblabla<b>&range=400&</b>stringandsoon... I successfully matched the "range=100"-part with alert( string.match(/range=100/) ...

delete multi-line block of text with internal flag in povray file

I have a pov-ray file, which defines a lot of cylinders and spheres. Sometimes these shapes are defined to have "color@", which makes the povray unrenderable. One solution I've found is to delete the offending cylinders and spheres. So a file that contains this text cylinder { < -0.17623, 0.24511, -0.27947>, < -0.15220, ...

Multiple Regex on String

How can I apply multiple regexs to a single string? For instance, a user inputs the following into a text area: red bird blue cat black dog and I want to replace each carriage return with a comma and each space with an underscore so the final string reads as red_bird,blue_cat,black_dog. I've tried variations in syntax along the line...

Tab Delimited to Comma Separated file in UNIX - One liner?

I have a tab delimited file (MySQL Out file). I want to convert it into CSV file. I got everything working except for replacing NULLs to nothing or spaces. What I have is : sed -e 's/^/"/; s/$/"/; s/\t/","/g;' < file.csv > file1.csv How to also replace NULLs in the same line. The following doesn't work. sed -e 's/NULL//; s/^/"/; s/$...

Find and Replace RegEx question

I am starting to get a grip on RegEx thanks to all the great help here on SO with my other questions. But I am still suck on this one: My code is: StreamReader reader = new StreamReader(fDialog.FileName.ToString()); string content = reader.ReadToEnd(); reader.Close(); I am reading in a text file and I want to search for thi...

Find and Replace RegEx with wildcard search and addition of value

The below code is from my other questions that I have asked here on SO. Everyone has been so helpful and I almost have a grasp with regards to RegEx but I ran into another hurdle. This is what I basically need to do in a nutshell. I need to take this line that is in a text file that I load into my content variable: X17.8Y-1.Z0.1G0H...

jQuery - Change background of input field if text getting replaced

I'm currently using jQuery to restrict a text box to number only input as follows: $('input.numbersOnly').keyup(function () { this.value = this.value.replace(/[^0-9\.]/g,''); }); I'd like to let the user know that what they are typing is being rejected by changing the background color of the field. I know that I can c...

sed: search and replace string with line number

Hi volks, I have a XML file with a lot of empty tag attributes. For instance: <mytag id=""> <ontent>aaa</content> </mytag> <mytag id=""> <ontent>bbb</content> </mytag> <mytag id=""> <ontent>ccc</content> </mytag> Now I want to replace id="" with e.g. id="2443" (id="[linenumber]") I tried to do this with sed, but I did not get ...

Post Loading ads - using appendChild to move an IFRAME with text link ads

I have changed code around to basically load an add the bottom of the page in a hidden div and attached an onload event handler that called document.getElementById(xxx).appendChild() to take the hidden ad and move it into the right spot in my page. This works GREAT.. however when the ad is a text ad it AFTER i move the ad there is nothi...

Complex pattern replacement using PHP preg_replace function ignoring quoted strings

Consider the following string: this is a STRING WHERE some keywords ARE available. 'i need TO format the KEYWORDS from the STRING' In the above string keywords are STRING and WHERE Now i need to get an output as follows: this is a <b>STRING</b> <b>WHERE</b> some keywords ARE available. 'i need TO format the KEYWORDS from the ...

How can I remove certain characters from inside angle-brackets, leaving the characters outside alone?

Edit: To be clear, please understand that I am not using Regex to parse the html, that's crazy talk! I'm simply wanting to clean up a messy string of html so it will parse Edit #2: I should also point out that the control character I'm using is a special unicode character - it's not something that would ever be used in a proper tag unde...

in tcl, how do I replace a line in a file?

let's say I opened a file, then parsed it into lines. Then I use a loop: foreach line $lines {} inside the loop, for some lines, I want to replace them inside the file with different lines. Is it possible? Or do I have to write to another temporary file, then replace the files when I'm done? e.g., if the file contained AA BB and ...

Question about the String.replaceAll() and String.replaceFirst() method.

I need to do a simple string replace operation on a segment of string. I ran into the following issue and hope to get some advice. In the original string I got, I can replace the string such as <div class="more"> to something else. BUT, in the same original string, if I want to replace a much long string such as the following, it won’t...

multi_index composite_key replace with iterator

Is there anyway to loop through an index in a boost::multi_index and perform a replace? #include <iostream> #include <string> #include <boost/multi_index_container.hpp> #include <boost/multi_index/composite_key.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/ordered_index.hpp> using namespace boost::multi_index...

Maven: properties not being substituted

I'm using a maven plugin for install4j in my project, located here. That plugin lets you pass variables to install4j using the <compilerVariables> section. Here's the relevant section of my pom: <plugin> <groupId>com.google.code.maven-install4j</groupId> <artifactId>maven-install4j-plugin</artifactId> <version>0.1.1</version...

Find and replace question regarding RegEx.Replace

Hello, I have a text file and I want to be able to change all instances of: T1M6 to N1T1M6 The T will always be a different value depending on the text file loaded. So example it could sometimes be T2M6 and that would need to be turned into N2T2M6. The N(value) must match the T(value). The M6 will always be M6. Another example:...

js - using replace method to replace html element

hi everyone! i have a question. I have a work this morning but i don't know how to do it. My work here (html): <div class="demo"> <p>this is demo text</p> </div> here is my JS : var tempdata = $(".demo").text(); var replacedata = tempdata.replace("text","<span>1234</span>"); Look everything ok. but result is : this is demo <spa...