search-and-replace

php / sql search

Hi, I want to find articles when searched on following keyword: "maruti sx4 maintenance costs against honda city" I want a query or php regular expression which can find a article which having below text "SX4 maintenance cost is lesser because of Maruti. Honda City maintenance is also okay." i.e i want a function/code which can fi...

How can I search for a character the displays as <85> in Vim?

I have a file that was converted from EBCDIC to ASCII. Where there used to be new lines there are now characters that show up as <85> (a symbol representing a single character, not the four characters it appears to be) and the whole file is on one line. I want to search for them and replace them all with new lines again, but I don't know...

Replacing quote marks around strings in Vim?

I have something akin to <Foobar Name='Hello There'/> and need to change the single quotation marks to double quotation marks. I tried :s/\'.*\'/\"\0\" but it ended up producing <Foobar Name="'Hello There'"/>. Replacing the \0 with \1 only produced a blank string inside the double quotes - is there some special syntax I'm missing that I ...

Matching one-line JavaScript comments (//) with re

I'd like to filter out (mostly one-line) comments from (mostly valid) JavaScript using python's re module. For example: // this is a comment var x = 2 // and this is a comment too var url = "http://www.google.com/" // and "this" too url += 'but // this is not a comment' // however this one is url += 'this "is not a comment' + " and ' ne...

Why does Perl replace my string with "1"?

I have the following code: #$domain = domainname.co.uk #$root = public_html #$webpage = domainname.co.uk/foo/bar/foobar.html my $string = ($webpage =~ s/^$domain//g); my $linkFromRoot = $dbh->quote($root . $string); Usualy this works fine but for some reason the output is "public_html 1" instead of "public_html/foo/bar/foobar.html". ...

Powerful search-replace GUI app for Mac?

What's the best dedicated search-and-replace GUI tool on a Mac? "Find & Replace It!" seems decent, but they've ridiculously disabled the replace function in the demo, so I can't give it a real test before paying. Is there anything else comparable or better? ...

Word 2007 Arabic Macro Replace

I am trying to manipulate Arabic in Word 2007. I need to find a line that begins with a number. In English docs I would use "^p^#" But in the Arabic doc I have, this isn't being found. Here's a snippet of text where a line starts with ٦٤ا : - ١٦٤يا معشر البشر تمسّکوا بالحبل المتين انّه ينفعکم فی الارض من لدی اللّه ربّ العالمين خذوا...

C# How to replace parts of one string with parts of another

Using C#, what's the most efficient way to accomplish this? string one = "(999) 999-9999"; string two = "2221239876"; // combine these into result result = "(222) 123-9876" String one will always have 9's. I'm thinking some kind of foreach on string one and when it sees a 9, replace it with the next character in string two. Not qui...

PHP: Changing or padding an array's key names

I have the following array: $person = array('first_name' => 'Fred', 'last_name' => 'Flintstone'); I want to change/pad the keys so the array will end up as (note extra colons): $person = array('::first_name::' => 'Fred', '::last_name::' => 'Flintstone'); For some reason I'm drawing a blank on the simplest way to do this ...

Position of a character in a NSString or NSMutableString

Hello, I have searched for hours now and haven't found a solution for my problem. I have a NSString which looks like the following: "spacer": ["value1", "value2"], "spacer": ["value1", "value2"], ... What I want to do is to remove the [ ] characters from the string. It's seems to be impossible with objective-c. Most other programming...

replacing a path with sed

How can I use sed to replace this line char * path_list_[1] = { "/some/random/path" }; with this line char * path_list_[2] = { "lib/foo", "lib/bar" }; in a file named source.c Notes: * The path is really random. * Your solution should only change this line in source.c * I'm only interested in a sed oneliner. You can use this Pyth...

Highlite words from searchstring

Hi, I wrote a little search script for a client, it works and words get highlited, BUT... Imagine this situation: search term: test found result: Hello this <a href="/news/this-is-a-test">is a test</a> In this example both 'test' in the href part and between the <a> tags get highlited, breaking the link. How could I prevent this? ...

Regex: Search and replace left side = to right side

How do I use regular expressions and search and replace to turn this [UserID] = <UserID, int,> [UserID] = 123123 [UserID] = asd123123 into [UserID] = [UserID] [UserID] = [UserID] [UserID] = [UserID] In other words I want to take everything from left side of the line up to the '=' character and replace everything on the right side o...

Editing a 9gb .sql file

Hi. I've got a "slightly" large sql script saved as a textfile. It totals in at 8.92gb, so it's a bit of a beast. I've got to do some search and replaces in this file(specifically, change all NOT NULL to NULL, so all fields are nullable) and then execute the darned thing. Does anyone have any suggestions for a text editor that would be ...

Regex for circular replacement

How would you use regex to write functions to do the following: Replace lowercase 'a' with uppercase and vice versa If easily extensible, do this for all letters Where words are separated by whitespaces and > and < are special markers on some words, replace >word with word< and vice versa. If it helps, you can restrict input such th...

vim: search replace over all writable buffers

so 1GvG:s/..../g can replace over an entire buffer However, suppose I have multiple vim buffers loaded, and I want to do a :s over all the buffers that are writable; is there a way to do this in vim? ...

Searching and replacing brackets in a string in Oracle 10G

I am currently developing a function that is meant to execute dynamically created SQL statements. This is done by concatenating the columns and fetching them via cursors. The problem is that when there is a function with a comma between its arguments, the concat concatenates the contents of the functions inclusive. Is it possible to ski...

php define variable inside str_replace array

I have a template system, that replaces text such as {HEADER} with the appropriate content. I use an array like this, that replaces the key with the value using str_replace. $array = array("HEADER","This is the header"); foreach($array as $var => $content) { $template = str_replace("{" . strtoupper($var). "}", $content,$templ...

Is str.replace(..).replace(..) ad nauseam a standard idiom in Python?

For instance, say I wanted a function to escape a string for use in HTML (as in Django's escape filter): def escape(string): """ Returns the given string with ampersands, quotes and angle brackets encoded. """ return string.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').repla...

"Simple" Text replace function

I have a string which is basically a list of "words" delimited by commas. These "words" can be pretty much any character e.g. "Bart Simpson, Ex-girlfriend, dude, radical" I'm trying to use javascript, jQuery, whatever i can to replace a word based on a search string with nothing (in essence, removing the word from the list). For exampl...