substitution

Perl qr// and substitution.

Hi guys. I'm writing a tiny program that takes user input using Getops, and based on it, the program will either try to match a pattern against some text, or substitute text for what matched. The problem I'm having is that I can't get the substitution portion to work. I'm looking at the qr// entry in the man pages: http://perldoc.perl....

Substitutions inside links in reST / Sphinx

I am using Sphinx to document a webservice that will be deployed in different servers. The documentation is full of URL examples for the user to click and they should just work. My problem is that the host, port and deployment root will vary and the documentation will have to be re-generated for every deployment. I tried defining substi...

Render a ASP.NET control in the master page code-behind

I'm using a Substitution control in my master page, and I want to render a user control content (related to the login area of my website) in the Substitution . Seems like I must have a reference for the requested page so that it could render the control. But I need to render the control in the master page itself, as it's shared across mu...

What Letter and Number Mixups Need to be Considered?

I just had a user tell me his registration key didn't work. It took me quite a while to figure out that he entered the capital letter "O" instead of the number "0". So I decided that it is best for my registry checker to treat both "O" and "0" as equivalent, so both will work. I can think of two other possible mixups: The number "1...

command substitution but without breaking output into multiple arguments

Is there a way to do command substitution in BASH shell without breaking output into multiple arguments? I copy the path of some directory (from the location bar in a GUI file browser) to clipboard and then issue the following command, where the command xsel returns the clipboard content, which is the path of the directory in this case:...

How can I preserve whitespace when I match and replace several words in Perl?

Let's say I have some original text: here is some text that has a substring that I'm interested in embedded in it. I need the text to match a part of it, say: "has a substring". However, the original text and the matching string may have whitespace differences. For example the match text might be: has a substring or has a s...

In VIM, is it possible to use the selected text in the substitute clause without retyping it?

Let's say I have a word selected in visual mode. I would like to perform a substitution on that word and all other instances of that word in a file by using s//. Is there a way to use the highlighted text in the s/<here>/stuff/ part without having to retype it? ...

Regular Expression for Conditional Substitution of Angle Brackets

Is it possible to create a single regexp to replace < and > with their entity equivalents? s/<|>/&lt;|&gt;/ ...

how to replace latex macros with their definitions (using latex)

How can I replace all occurrence of user defined latex macros with their definitions? For example, given this file old.tex \newcommand{\blah}[2]{#1 \to #2} ... foo \blah{egg}{spam} bar ... how to generate the file below in an automatic way new.tex ... foo egg \to spam bar ... Instead of reimplementing latex macro logic with perl...

rails - :joins sanitizing/substitution

is it possible to specify parameters for :joins similar way as for :conditions? here is an example (sql code is irrelevant) named_scope :threads, { :joins => [" LEFT JOIN groups_messages gm ON messages.id=gm.message_id AND gm.group_id IN (?) ",@group_ids_array], :conditions => ["creator_id=? AND messages.id IN (?)", current_user_i...

How do I use Perl to intersperse characters between consecutive matches with a regex substitution?

The following lines of comma-separated values contains several consecutive empty fields: $rawData = "2008-02-06,8:00 AM,14.0,6.0,59,1027,-9999.0,West,6.9,-,N/A,,Clear\n 2008-02-06,9:00 AM,16,6,40,1028,12,WNW,10.4,,,,\n" I want to replace these empty fields with 'N/A' values, which is why I decided to do it via a regex substitution. ...

Is $1 or $& faster for replacing a matched string using s/// in Perl?

Which one of these is cheaper? $_ = 'abc123def'; s/\d+/$&*2/e; say; s/(\d+)/$1*2/e; say; ...

VIM substitution: Using the current line as the search string

Assuming the following text file, which is actually a data dump of funds and price statistics: PBCPDF 05/01/2006 0.0000 0.0000 PBCPDF 0.0000 06/01/2006 0.0000 0.0000 PBCPDF 0.0082 [… lines repeat …] What I wanted to achieve is to delete all instances of PBCPDF except for the first one, which I could write the substitution comman...

Windows Shell Script: Can't make string substitution working in subroutine...

Greetings dear Experts! Could you please advice me on how to cope with the problem: @echo off cls setlocal enabledelayedexpansion path=%CD%;%path% set NumberOfPages=553 rem set /A MaxFileIndex=%Counter% - 1 set MaxFileIndex=1 del Output.txt for /l %%i in (0,1,%MaxFileIndex%) do call :GenerateFileList %%i goto :eof :::::::::::::...

Is there a way to access the current session from within a substitution control ?

Looks like context parameter of asp:net substitution control method is missing the current session once the page is output cached. Aside from getting the substitution control's content thru ajax or using some other method to store data that would otherwise be in session (like database) is there anything else I can do? Is there a workar...

Shell aliasing multiple arguments

Is there a good way to do multiple substitutions for aliasing a command? For example alias cmd = 'ssh -R $1:$2:$1:$2 $3 | something {$1, $2, $3}' cmd 127.0.0.1 1234 server Something like this.. Actually, this doesn't really make any sense to pipe the output like this, but similar syntax is what I'd like to see. It's be nice to have...

Log4J – Runtime variable substitution

Log4J appears to have an annoying restriction – at runtime, variable substitution does not appear to work. In this example File: Log4j.properties file_pattern=%d{ISO8601} %-5p %m%n log4j.rootLogger=DEBUG, FileAppender log4j.appender.FileAppender=org.apache.log4j.FileAppender log4j.appender.FileAppender.layout=org.apache...

How do I substitute from a list of strings in VIM?

Hi, I am a vim user, and I want to be able to loop over a range of substrings when I am substituting. How can I use some vim magic to go from a set of lines like this: Afoo Bfoo Cfoo Dfoo to Abar Bbar Cbaz Dbaz ??? I want to search my file from the start for the next occurance of foo, and replace the first two instances with bar...

How do I replace "\" with "//" in Perl?

I want to substitute, the "\" that appears in the Windows directory link to a "/". I tried using s//\////g, but it doesn't seem to do the trick. ...

ASP.NET response filtering and post-cache substitution are not compatible

According to this article http://support.microsoft.com/kb/2014472 you can't use Response filters and Substitution controls together. Has anyone found a workaround for this? I am trying to process complete HTML response just before it's written to client and I do use substitution controls widely. ...