escaping

Escape Java RegExp Metacharacters

China☆狼群 提交于 2021-02-05 07:25:46
问题 I'm trying to escape a RegExp metacharacter in Java. Below is what I want: INPUT STRING: "This is $ test" OUTPUT STRING: "This is \$ test" This is what I'm currently doing but it's not working: String inputStr= "This is $ test"; inputStr = inputStr.replaceAll("$","\\$"); But I'm getting wrong output: "This is $ test$" 回答1: You'll need: inputStr.replaceAll("\\$", "\\\\\\$"); The String to be replaced needs 2 backslashes because $ has a special meaning in the regexp. So $ must be escaped, to

Trouble escaping dollar sign in Perl

会有一股神秘感。 提交于 2021-02-05 05:41:11
问题 I'm getting a bunch of text from an outside source, saving it in a variable, and then displaying that variable as part of a larger block of HTML. I need to display it as is, and dollar signs are giving me trouble. Here's the setup: # get the incoming text my $inputText = "This is a $-, as in $100. It is not a 0."; print <<"OUTPUT"; before-regex: $inputText OUTPUT # this regex seems to have no effect $inputText =~ s/\$/\$/g; print <<"OUTPUT"; after-regex: $inputText OUTPUT In real life, those

Trouble escaping dollar sign in Perl

我是研究僧i 提交于 2021-02-05 05:40:49
问题 I'm getting a bunch of text from an outside source, saving it in a variable, and then displaying that variable as part of a larger block of HTML. I need to display it as is, and dollar signs are giving me trouble. Here's the setup: # get the incoming text my $inputText = "This is a $-, as in $100. It is not a 0."; print <<"OUTPUT"; before-regex: $inputText OUTPUT # this regex seems to have no effect $inputText =~ s/\$/\$/g; print <<"OUTPUT"; after-regex: $inputText OUTPUT In real life, those

Escape string with PHP and HTML

风格不统一 提交于 2021-02-04 19:46:06
问题 I have these two lines that I would like to escape the $type variable: $functionName = str_replace('-', '_', $type); $output .= '<div class="tab-pane" id="'. $type .'">'; I tried escaping like below but its confusing me and not sure whether thats right: $output .= '<div class="tab-pane" id="\'. $type .'\">'; 回答1: Example 1: Variable between single quotes If you use single quotes everything between them will always be treated as part of the string. $output .= '<div class="tab-pane" id="' .

Strange CSV result for quoted strings in go encoding/csv

流过昼夜 提交于 2021-02-04 18:48:47
问题 I have this little bit of code that kept me busy the whole weekend. package main import ( "encoding/csv" "fmt" "log" "os" ) func main() { f, err := os.Create("./test.csv") if err != nil { log.Fatal("Error: %s", err) } defer f.Close() w := csv.NewWriter(f) var record []string record = append(record, "Unquoted string") s := "Cr@zy text with , and \\ and \" etc" record = append(record, s) fmt.Println(record) w.Write(record) record = make([]string, 0) record = append(record, "Quoted string") s =

escaping the double quotes in python string

左心房为你撑大大i 提交于 2021-01-29 15:50:54
问题 I've a question about double quotes escaping in python string formatting. for example, print "How tall are you?", height = raw_input() print "So you are %r tall" % height when I put 5" 6' , it returns ' 5\'6" ' and i don't get why there is a backslash. 回答1: You're asking for the representation of the string. Since the string contains both types of quotes, one type must be escaped in order for it to be a proper representation. If you only want what was typed then use %s instead. 来源: https:/

Escape correctly double quotes

≯℡__Kan透↙ 提交于 2021-01-28 18:36:52
问题 I have the following two commands executed inside a pipeline def IMAGE = "url/microservices/currency-converter-search:${env.BUILD_NUMBER}" sh "cat task-blueprint.json | jq .containerDefinitions[0].image=${IMAGE} > currency-converter-search-task-${env.BUILD_NUMBER}.json" the problem is that I get back an error because the string that I need to save need to be surrounded by " double quote in order to be save by jq This is the error I get: [workspace] Running shell script + jq

Escape correctly double quotes

南笙酒味 提交于 2021-01-28 18:36:00
问题 I have the following two commands executed inside a pipeline def IMAGE = "url/microservices/currency-converter-search:${env.BUILD_NUMBER}" sh "cat task-blueprint.json | jq .containerDefinitions[0].image=${IMAGE} > currency-converter-search-task-${env.BUILD_NUMBER}.json" the problem is that I get back an error because the string that I need to save need to be surrounded by " double quote in order to be save by jq This is the error I get: [workspace] Running shell script + jq

Stubborn Ampersand with Invoke-Webrequest SQL & Powershell

北城以北 提交于 2021-01-28 11:43:22
问题 When I run powershell using invoke-webrequest on a URL without an ampersand everything works. But my URL's have ampersands in them. If I surround them by double quotes it works from PowerShell, but not if I am doing it through my SQL Server. Trying to get the right combination of escape characters is proving to be a pain in the butt. Here's an example of the command: exec xp_cmdshell 'powershell Invoke-WebRequest -UseBasicParsing -Uri "https://example.com/getfile/12345&i=123" -outfile C:

What are the differences in echo between zsh and bash?

喜夏-厌秋 提交于 2021-01-28 10:56:20
问题 In bash, in this specific case, echo behaves like so: $ bash -c 'echo "a\nb"' a\nb but in zsh the same thing turns out very differently...: $ zsh -c 'echo "a\nb"' a b and fwiw in fish, because I was curious: $ fish -c 'echo "a\nb"' a\nb I did realize that I can run: $ zsh -c 'echo -E "a\nb"' a\nb But now I am worried that I'm about to stumble into more gotchas on such a basic operation. (Thus my investigation into fish: if I'm going to have to make changes at such a low level for zsh, why not