replace

What is the difference between [Regex]::Replace() and -replace?

房东的猫 提交于 2020-01-02 10:05:27
问题 I understood the difference between .Replace() and -replace , but what are -replace and [Regex]::Replace() ? I tested the 2 following codes, but for me the results are the exactly the same. I also referred to PowerShell Cookbook(O'reilly), and it says ([Regex] is) extremely advanced regular expression replacement I want to know what [Regex] can but -replace can't. $line = "Loosen the socket by turning it#counterclockwise." $line = $line -Replace "([a-z])#([a-z])","`$1 `$2" $line # Loosen the

IntelliJ structural search and replace problems

跟風遠走 提交于 2020-01-02 08:58:34
问题 Is there an easy way to capture types? I can't seem to do basic things like use variable expressions side by side, such as $mapType$$mapEnd$ to do a simple replacement. Is there any reason this might be? That is, if I have a single expression, say .*\s*.*abc , and I break it into two variables, .*\s* and .*abc , the expression does not match any text. What could be going wrong? Example template: $var1$ = $impl$ Example second template: $var1$ = $type$$implEnd$ If $impl$ is a full regular

How to search/replace expressions with parantheses in emacs?

我只是一个虾纸丫 提交于 2020-01-02 08:46:30
问题 I have a bit of Latex code with lots of maths expressions enclosed in \mathrm{}. I'd like to remove the \mathrm{} code around the expressions, preferrably using emacs. For example, I'd like to substitute \mathrm{\gamma \cdot x_0} with \gamma \cdot x_0 Removing \mathrm{ only is easy, but I also need to remove the closing bracket. How can I do this in emacs? Many thanks, Enno 回答1: You can use back references to tackle this problem. Run M-x query-replace-regexp and enter \\mathrm{\([\a-z0-9_ ]+\

Find and replace variables containing non-escaped characters with sed

孤人 提交于 2020-01-02 08:29:39
问题 I can use this, to find all instances of "fly" and replace it with "insect" in my file: sed -i 's/fly/insect/g' ./animals.txt How can I find a BASH variable and replace it with another BASH variable? E.g.: name=$(echo "fly") category=$(echo "insect") sed -i 's/$name/$category/g' ./animals.txt Update: I am using GNU sed version 4.2.1. When I try the solutions below, it reports this error: sed: -e expression #1, char 73: unknown option to `s' Update: I discovered why the error is coming up.

Bash: any command to replace strings in text files?

冷暖自知 提交于 2020-01-02 07:10:25
问题 I have a hierarchy of directories containing many text files. I would like to search for a particular text string every time it comes up in one of the files, and replace it with another string. For example, I may want to replace every occurrence of the string "Coke" with "Pepsi". Does anyone know how to do this? I am wondering if there is some sort of Bash command that can do this without having to load all these files in an editor, or come up with a more complex script to do it. I found this

replace image through css

走远了吗. 提交于 2020-01-02 04:20:40
问题 I'm writing code in Stylish, a firefox plugin, to change the image that is showing up. The image property doesn't have a div tag, so I have to use this: img[src*="s_dschjungelplanet"]{ ########## } So this will replace "s_dschjungelplanet" anywhere in the page, in a img src. So my main problem is that I'm not sure HOW to tell it to replace the src="xxx". Ta for replies 回答1: There is no easy way. I think you'd be better of with greasemonkey scripts, as with a simple such script you can change

Javascript - replace string between brackets, but the brackets should stay

走远了吗. 提交于 2020-01-02 02:52:11
问题 I'd like to replace character inside a string, e.g. Drafts [ 2 ] To: Drafts [ 3 ] This regex returns only Drafts 3 : str.replace(/\[(.+?)\]/g, 3) Thanks for help in advance 回答1: Do you need something more than below? var num=2 // parse this from drafts [2] num++; var newstr=str.replace(/\[(.+?)\]/g, "["+num+"]") Or the brackets can change to <> {} per input? You can also give a function instead of the replace-string. var str = "Drafts [2]"; function replacer(match, p1, p2, p3, offset, string)

Simple excel find and replace for formulas

这一生的挚爱 提交于 2020-01-02 00:48:27
问题 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((LN(E9/E8)/14.32))-1) . How can I change them all to the new formula in one fell swoop? 回答1: If the formulas are identical you can use Find and Replace with Match entire cell contents checked and Look in: Formulas . Select the range, go into Find and Replace, make your entries and `Replace All. Or do you mean that there are several

Replacing one character with another in a string

谁都会走 提交于 2020-01-01 23:58:24
问题 I have a data like below: A:B:C:D and I want to replace the C with data (say, Z ) so that it may look like A:B:Z:D How can I do it? 回答1: =SUBSTITUTE(A1,"C","Z") Although I wasn't clear on whether you wanted G or Z , you mentioned G but your example output shows Z . 回答2: If you have A:B:C:D in cell A1, then this works: =CONCATENATE(MID(A1, 1, SEARCH(":", MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH(":", A1) + 1)) + SEARCH(":", A1)), "Z", MID(MID(MID(A1, SEARCH(":", A1) + 1, LEN(A1) - SEARCH("

Add before and after the string

南笙酒味 提交于 2020-01-01 19:59:10
问题 $variable = 'for linebreak add 2 spaces at end'; Value of this variable everytime changes. How to add some text or html before and after this string? E.g. if we want to add '<div>' before and '</div>' after, string should look like: $variable = '<div>for linebreak add 2 spaces at end</div>'; 回答1: Marko's solution is the way to go for simple cases. If you need to concatenate many strings, it is said that joining arrays is much faster. $string[]='<div>'; $string[]= $variable; $string[]='</div>'