I'm unsure why this is happening but whenever I do the following
<img src=\"Images\\{reader[2]}\" onmouseover=\"this.src='Images\\White\\{reader[2]}';\">
It outputs the following in the source code
<img onmouseover="this.src='Images\White\settings.png';" src="ImagesWhitesettings.png">
Why is it removing the backslashes?
A \ indicates the start of an escape sequence in a JavaScript string literal.
To include \ as data you have to use the escape sequence for it: \\.
That said, URLs use / and not \ as path separators.
Try using forward slashes "/", because backslashes are used to escape characters.
Related
Apologize for such dummy question but this is my first time using curl command and now I got this command from somewhere to extract the following string
{"success":true,"results":1,"total":1,"more":false,"offset":0,"hits":[{"path":"/home/users/Vq7DPVRHzGVK--OTJsHs","excerpt":"","name":"Vq7DPVRHzGVK--OTJsHs","title":"Vq7DPVRHzGVK--OTJsHs","lastModified":"2017-03-03
16:45:46","created":"2017-03-03 16:45:46"}]}
I pipe the curl output to sed with the following script:
sed -e 's/^.*"path":"\([^"]*\)".*$/\1/
Result:
/home/users/Vq7DPVRHzGVK--OTJsHs
Can anyone explain how's the regex work here? and how do I get the result for only Vq7DPVRHzGVK--OTJsHs instead of including the /home/user path?
Explanation:
s/ ^.*"path":"\([^"]*\)".*$ / \1 /
----------^------------ ---^---
Pattern Replacement string
How does Regular Expression work:
^.* # Match beginning of input string & anything else
"path":" # Up to literal string `"path":"`
\([^"]*\) # Then match slash and match + group anything up to a double quote `"`
".*$ # Match double quote and the rest of input string
By replacement string \1 you are replacing whole matching part with first capturing group which is every thing between double quotes of path value except the beginning slash.
What you want is changing capturing group from capturing whole part to last section:
s/^.*"path":"[^"]*\/\([^"]*\)".*$/\1/
Regex demo
Regex: .*"path\":"\K[\/\w]+(?=\/)\/\K[^"]+
So I got a string that has a backslash in it. "kIurhgFBOzDW5il89\/lB1ZQnmmY=".
I tried adding an extra '\', but JSON.stringify( "kIurhgFBOzDW5il89\\/lB1ZQnmmY=") returns the string with two backslashes instead of one. Is there any way to keep the backslash using JSON.stringify?
JSON.stringify doesn't remove the backslash, it encodes it. When you use JSON.parse on the other end, or whatever you do to decode your JSON, it will return the original string.
The backslash is escaping the forward slash. So JSON.stringify("\/") returns "/" since it sees an escaped forward slash, so its just a forward slash. JSON.stringify("\\/") sees a backslash being escaped, and then a forward slash next to that, so it returns "\/". You cannot preserve the "exact" string when you stringify, since parsing a json string will not escape characters, so you get back your original data, just unescaped.
JSON.parse(JSON.stringify("kIurhgFBOzDW5il89\\/lB1ZQnmmY="))
// "kIurhgFBOzDW5il89\/lB1ZQnmmY="
I was just wondering why my wcf rest returns json which contains backslahses in the url. it is as below:
https:\/\/s3.amazonaws.com\/reiaustralia\/1fc00dfab25044ecb31e4882121b535e\/jpg\/download.jpg?AWSAccessKeyId=AKIAISTDESL6TBRAVM4Q&Expires=1380692091&Signature=MduuaUAjQRisadtM%2FDuVDemexLY%3D
Thanks
Forward slashes can be escaped with a backslash in JSON, but they don't have to be. So either one of the following:
{"url":"http://www.example.com/"}
or
{"url":"http\/\/www.example.com\/"}
Will parse into an object which has a url property whose string value is http://www.example.com/.
Some technologies will escape out the slashes when generating JSON, and some won't. PHP, for example, has an option called JSON_UNESCAPED_SLASHES which lets you control whether or not to escape your slashes.
You can get see the various escape characters from the json.org home page in the "string" section.
Because // (double slash) in javascript means comment and /{string}/ (string inside slash) is mean regula expression.
So. To keep correct value in json it have to put \ (back slash) in front of / (slash).
They are just escape characters, and when u consume the string in your application it would just be fine
I'm using Kramdown and Octopress to write markdown text, but I don't know how to get \\ in html. I tried \\\\ but get \. According to its doc, \ is used for escape. Does anyone know how to get \\ in html, not \\? thanks. And I'm confused about when \\ will be translated into \ and when will be <br />.
The problem is not with Kramdown, but with a plugin that comes with Octopress called rubypants.rb. Take a look at plugins/rubypants.rb, and you will find a method named process_escapes which does several calls to str.gsub. (Line 335 or so.) One of these replaces the double backslash ("\") with the escape code you're seeing - fix that line and you'll be good. (You can fix it by moving the 'str.' to the next gsub and deleting the rest of the line.)
I am not seeing the problem here
$ kramdown --version
0.14.2
$ kramdown <<< '\\\\'
<p>\\</p>
I am loading a html page(UTF-8) content using UrlLoader. All characters in the result are represented as //x?? (where ?? is one symbol).
How can I get normal string from this? (with actual symbols instead of codes).
Usually, in languages such as lua. An escape character can be followed by the same escape character to do the character so:
\ -> \
and
\n -> /n
I don't really know actionscript but I bet you could replace the escape character with two.
Basically replace \ (assuming \ is the escape character (it normally is in most languages)) with \.