replace

Non-capturing group matching whitespace boundaries in JavaScript regex

断了今生、忘了曾经 提交于 2020-01-21 12:20:29
问题 I have this function that finds whole words and should replace them. It identifies spaces but should not replace them, ie, not capture them. function asd (sentence, word) { str = sentence.replace(new RegExp('(?:^|\\s)' + word + '(?:$|\\s)'), "*****"); return str; }; Then I have the following strings: var sentence = "ich mag Äpfel"; var word = "Äpfel"; The result should be something like: "ich mag *****" and NOT: "ich mag*****" I'm getting the latter. How can I make it so that it identifies

sed is printing a substituted line twice

和自甴很熟 提交于 2020-01-21 09:08:30
问题 I am running the following command: find /home/debajdas/checkout -name 'pom.xml' -or -name '*.properties' | xargs sed -i 's/10.0.0.0.3/10.0.0.0.4/gpw changes' But it's replacing <version>10.0.0.0.3</version> with <version>10.0.0.0.4</version> <version>10.0.0.0.4</version> Why is it getting replaced with 2 lines ? 回答1: You must remove 'p' that prints current pattern space. sed -i 's/10\.0\.0\.0\.3/10.0.0.0.4/gw changes' 回答2: GNU sed sed -i 's/\.3/.4/w changes' 来源: https://stackoverflow.com

sed is printing a substituted line twice

邮差的信 提交于 2020-01-21 09:07:51
问题 I am running the following command: find /home/debajdas/checkout -name 'pom.xml' -or -name '*.properties' | xargs sed -i 's/10.0.0.0.3/10.0.0.0.4/gpw changes' But it's replacing <version>10.0.0.0.3</version> with <version>10.0.0.0.4</version> <version>10.0.0.0.4</version> Why is it getting replaced with 2 lines ? 回答1: You must remove 'p' that prints current pattern space. sed -i 's/10\.0\.0\.0\.3/10.0.0.0.4/gw changes' 回答2: GNU sed sed -i 's/\.3/.4/w changes' 来源: https://stackoverflow.com

sed is printing a substituted line twice

ぃ、小莉子 提交于 2020-01-21 09:07:40
问题 I am running the following command: find /home/debajdas/checkout -name 'pom.xml' -or -name '*.properties' | xargs sed -i 's/10.0.0.0.3/10.0.0.0.4/gpw changes' But it's replacing <version>10.0.0.0.3</version> with <version>10.0.0.0.4</version> <version>10.0.0.0.4</version> Why is it getting replaced with 2 lines ? 回答1: You must remove 'p' that prints current pattern space. sed -i 's/10\.0\.0\.0\.3/10.0.0.0.4/gw changes' 回答2: GNU sed sed -i 's/\.3/.4/w changes' 来源: https://stackoverflow.com

Replace “&” to “\&” in Ruby seems impossible?

ぃ、小莉子 提交于 2020-01-21 05:17:17
问题 I want to replace all & characters into \& with String.gsub (or a other method). I've tried several combinations and read another question here, but nothing is gonna work. "asdf & asdf".gsub("&", "\\\&") => "asdf & asdf" 回答1: Your linked question provides a solution - use the block form of gsub : irb(main):009:0> puts "asdf & asdf".gsub("&"){'\&'} asdf \& asdf 回答2: I'm going to guess that you're using 1.8. In 1.8, irb says this: >> "asdf & asdf".gsub("&", "\\\&") => "asdf & asdf" >> puts

Replace multiple words with Str_Replace

白昼怎懂夜的黑 提交于 2020-01-21 05:15:08
问题 I want to replace multiple synonyms with one specific word. <?p $a = array( 'truck', 'vehicle', 'seddan', 'coupe', 'Toyota', ); $b = array( 'car', 'car', 'car', 'car', 'Lexus', ); $str = ' Honda is a truck. Toyota is a vehicle. Nissan is a sedan. Scion is a coupe. '; echo str_replace($a,$b,$str); ?> RESULT: Honda is a car. Lexus is a car. Nissan is a car. Scion is a car. Can someone show me a clean way of replacing "vehicle, truck, coupe, sedan" with the word "car" instead of me replacing all

Find and Replace with Regex in Microsoft Word 2013

寵の児 提交于 2020-01-21 02:38:11
问题 I am editing an e-book document with a lot of unnecessary markup. I have a number of sections in the text with code similar to this: <i>Some text here</i> I am trying to run a regex find and replace that will find any phrase between the two i-tags, remove the i-tags, and apply a style to the text. Here is what I'm using to search: Find: (<i>)(*)(</i>) Replace: \2 I'm also selecting Styles > i (for italic). This tells our conversion software to apply italics to the text. If I leave the i-tags,

C# hexadecimal value 0x12, is an invalid character

大兔子大兔子 提交于 2020-01-20 16:53:04
问题 I am loading a lot of xml documents and some of them return errors like "hexadecimal value 0x12, is an invalid character" and there are different character. How to remove them? 回答1: I made a small research here. Here is the ASCII table. There are 128 symbols Here is some small test code which adds every symbol from ASCII table and tries to load it as an XML document. static public void RegexTry() { StreamReader stream = new StreamReader(@"test.xml"); string xmlfile = stream.ReadToEnd();

xss-labs-游戏闯关8-10

房东的猫 提交于 2020-01-20 12:48:16
level8 这应该是一个存储型的xss </center><center><BR><a href="<scr_ipt>alert('xss')</scr_ipt>">友情链接</a></center><center><img src=level8.jpg></center> 参照level5 level6 先闭合<a>标签,然后采用不含<script>和on关键字的弹窗语句 "> <a hRef="javascript:alert(1)">xss</a>// 失败; 这次应该是转换成小写,然后对所有关键字替换为-,而不是为空; <?php ini_set("display_errors", 0); $str = strtolower($_GET["keyword"]); $str2=str_replace("script","scr_ipt",$str); $str3=str_replace("on","o_n",$str2); $str4=str_replace("src","sr_c",$str3); $str5=str_replace("data","da_ta",$str4); $str6=str_replace("href","hr_ef",$str5); $str7=str_replace('"','&quot',$str6); echo '<center>

如何分割字符串以便可以访问项目x?

ぐ巨炮叔叔 提交于 2020-01-20 12:39:39
使用SQL Server,如何分割字符串以便可以访问项x? 取一个字符串“ Hello John Smith”。 我如何按空格分割字符串并访问索引1的项目,该项目应返回“ John”? #1楼 我认为你们正在使它变得过于复杂。 只需创建CLR UDF并完成它即可。 using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; using System.Collections.Generic; public partial class UserDefinedFunctions { [SqlFunction] public static SqlString SearchString(string Search) { List<string> SearchWords = new List<string>(); foreach (string s in Search. Split (new char[] { ' ' })) { if (!s.ToLower().Equals("or") && !s.ToLower().Equals("and")) { SearchWords.Add(s); } }