replace

Quickie - replace all occurences of ' (apostrophe) with '' (two apostrophes) in an AnsiString (C++)

I think you can guess the problem I'm having. I'm inserting filenames in to an sql database in C++ Builder. Some files have an apostrophe in their name. This breaks the sql insert query. the usual way to fix this is to double up and apostrophes you want to be part of the field value. For example if I want to add 'george's' to field ...

PDF Search and Replace in C#

Hi, I want to perform a simple (ideally RegEx) search and replace over a large number of PDF documents in a WinForms application. I've got as far as using ITextSharp to read and tokenise existing documents, from which I can search for the text. The problem is that it doesn't seem to support generating new document from these tokens (onl...

XSLT 2.0, replace function: How to replace matched group with upper case?

Hello, If have a following element in my XSL file: <xsl:value-of select="replace(lower-case(@name), '_([a-z0-9])', '$1')" /> For example from 'get_polygene_lubricants' it makes 'getpolygenelubricants'. What I want to do is to replace the first letter after '_' with the uppercase variant of the letter. I googled, read documentation, ...

replacing regex in java string

I have this java string: String bla = "<my:string>invalid_content</my:string>"; How can I replace the "invalid_content" piece? I know I should use something like this: bla.replaceAll(regex,"new_content"); in order to have: "<my:string>new_content</my:string>"; but I can't discover how to create the correct regex help please :)...

Javascript search and replace

I would like do do the following in Javascript (pseudo code): myString.replace(/mypattern/g, f(currentMatch)); that is, replace string isn't fixed, but function of current match. ...

Remove brackets with regular expression in C#

I want to remove square brackets from an SQL string, but only where there is no whitespace inside them. E.g. "SELECT [intId], [The Description]" should return "SELECT intId, [The Description]". I can get the square brackets without spaces inside with the regular expression: \[[^\s]*\] How can the square brackets from these matches b...

Replace 2 strings at the same time?

hello how can I replace 2 strings in the same time? for example let's say I have string like this: str1 = "AAAA BBBB CCCC DDDD" i want to replace every "AAAA" with "CCCC" and every "CCCC" with "AAAA" but if i did: str1.gsub("AAAA","CCCC") # CCCC BBBB CCCC DDDD str1.gsub("CCCC","AAAA") # AAAA BBBB AAAA DDDD what I want str1 to be "C...

Best way to do a find/replace in several files?

Hey dudes, what's the best way to do this? i'm no command line warrior, but i was thinking there's possibly a way using grep and cat. i just want to replace a string that occurs in a folder and sub-folders. what's the best way to do this? i'm running ubuntu if that matters. -d ...

Is there a better way to write this javascript regex/replace?

The following code works, but I'm sure there is a more compact way to achieve the same result, particularly the string replacement: $('#nav-main .nav-sub').each(function() { var name = $(this).attr('id'); $(this).children('li').children('a').each(function() { var text = $(this).text().toLowerCase(); var spaces = / /g; var sub...

Search and replace multiple values with multiple/different values in PHP5?

Is there an inbuilt PHP function to replace multiple values inside a string with an array that dictates exactly what is replaced with what? For example: $searchreplace_array = Array('blah' => 'bleh', 'blarh' => 'blerh'); $string = 'blah blarh bleh bleh blarh'; And the resulting would be: 'bleh blerh bleh bleh blerh'. ...

Replacing tags with content in a simple template system

I'm trying to build a simple "User Template" system so that my users can edit the layout of RSS feed items and system-generated emails without messing with view files and such. This is the function I'm using to replace the tags in a string with content: private const string URL_TAG_REGEX = @"{{(?<TagName>\w*)}}"; private static string R...

How do I escape a left paren in a Perl regex?

If I have a file containing some escaped parens, how can I replace all instances with an unescaped paren using Perl? i.e. turn this: .... foo\(bar .... into this .... foo(bar .... I tried the following but receivied this error message: perl -pe "s/\\\(/\(/g" ./file Unmatched ( in regex; marked by <-- HERE in m/\\( <-- HERE / at ...

How to replace DevExpress ASP.NET calendar with my own?

We're using DevExpress control toolkit for our ASP.NET application. I would like to replace the DevExpress default dropdown calendar with my own because of the following reasons: DevExpress dropdown calendar gets positioned absolutely next to the textbox it is assigned to. This is bad, because on IE it gets obscured by other relatively...

How can I add * to the end of each line in Vim?

I tried the code unsuccessfully :%s/\n/*\n/g ...

Vim copy and paste

My previous question seems to be a bit ambiguous, I will rephrase it: I have a file like this: copythis abc replacethis1 xyz qwerty replacethis2 hasfshd replacethis3 fslfs And so on... NOTE: replacethis1, replacethis2, replacethis3, ... could be any words How do I replace "replacethis1","replacethis2","replacethis3",.. word by "copy...

How can I record changes made during in-place editing in Perl?

I've scripted up a simple ksh that calls a Perl program to find and replace in files. The passed-in arg is the home directory: perl -pi -e 's/find/replace/g' $1/*.html It works great. However, I'd like to output all the changes to a log file. I've tried piping and redirecting and haven't been able to get it work. Any ideas? Thank...

Replace content in a string based on Regex.Matches MatchCollection

I've been working on this RegEx for the past day or so and I think I have it worked out so that it returns the data I want. First a little background. I have a content editor that users will be able to edit web pages. They can format text, add links, etc.. standard content editor stuff. When they click save, the editor provides the ab...

Replace http:// in anchor portion of links using Jquery

Hi, on a page there a several links of: <a class="linked" href="http://link1.com&gt;http://link1.com&lt;/a&gt; <a class="linked" href="http://link2.com&gt;http://link2.com&lt;/a&gt; How would one remove the second http:// in each link so it can't be seen on the screen. I've tried this to no avail: $(document).ready(function() { $(...

Unable to replace different matches with a single replace in Vim

I tried the following code unsuccessfully :%s/{car,beatles}/mas/g How can I replace car and beatles with mas in Vim with a single command? ...

How can I search and then replace a code snippet that includes some variables in TextMate?

I have a project that includes 49 folders, each one has a file called index.php All index.php files are almost the same except for one part that changes depending on the folder it is in. <?php include_once("/home/bgarch/public_html/galleryheader.html"); ?> <?php include_once("/home/bgarch/public_html/culture/loadscripts.html"); ?> </h...