search for '-' in Azure Search query - json

I am using Azure Search and I want to search for this specific word with the dash in between:
Top-Light
My json post body is:
{
"search":"/(.*)top-light(.*)/",
"queryType":"full",
"top":1000
}
The result is empty because he replaces the "-" with empty "". so he is trying to search for toplight which does not exist.
I tried the escape character:
"search":"/(.)top-light(.)/"
and I received an error:
The request is invalid. Details: parameters : Invalid JSON. An unrecognized escape sequence '\-' was found in a JSON string value.
I tried to use:
\-
(-)
(-*)
(.*)
\\-
/-
and none of them works. Any suggestion?
thank you!

Just filter it as a string. [search.ismatch('"top-light"', '[whatever the field is]').

Related

MySQL- Insert single escape character into MySQL JSON field

In dealing with the headache of the different rulesets with TEXT escaping and JSON escaping, I've come across the issue where double escaping is required to convert a string to a JSON literal. For example, the original UPDATE looks like this:
UPDATE sourcing_item_data SET data_JSON='{"test": "test \ test"}' WHERE ID = 1;
The above simply removes the '\'.
The problem is I can't see how we get a single backslash into the system. Using two \'s causes the Invalid JSON error. Using three \'s does the same. Using four \'s puts in two \'s.
How does one get a single backslash into a JSON literal from a string with MySQL?
Also, has anyone written a SP or Function that scans a string that's supposed to be converted to MySQL JSON to ensure the string is "scrubbed" for issues (such as this one)?
Thanks!
Four backslashes works.
UPDATE sourcing_item_data SET data_JSON='{"test": "test \\\\ test"}' WHERE ID = 1;
You need to double the backslash to escape it in JSON, and then double each of those to escape in the SQL string.
If you print the JSON value it will show up as two backslashes, but that's because it shows the value in JSON format, which means that the backslash has to be escaped. If you extract the value and unquote it, there will just be one backslash.
select data_JSON->>"$.test" as result
from sourcing_item_data
WHERE id = 1;
shows test \ test
DEMO

Invalid data updating form error when updating textvalidation of item

I use the following code to update textvalidation with a string:
function updateform(strtokens) {
var form = FormApp.openById(#formid#);
var textItem = form.getItemById(#formid#);
var textValidation = FormApp.createTextValidation()
.requireTextMatchesPattern(strtokens)
.build();
textItem.asTextItem().setValidation(textValidation);
return form.getPublishedUrl();
}
I get error saying invalid data updating form at line textItem.asTextItem().setValidation(textValidation)
I get this issue on occasion but not all the time and i can't figure out why.
Are any of the following issues possible explanation?
strtokens is of the format: text1|text2|text3|.. etc, it can be very long. text1, etc also include special characters. note strtokens is concatenates randomly generated text of length 10 and the # of text is currently set to 10.
The text is generated by randomly sampling 10 characters from A-Z, a-z, 0-9 & special characters. please see examples below where they cause and do not cause error.
Does the form id/item id change so that it doesn't identify accurately? I got form id from the url and I got item id from inspecting the id in the html of the form.
Answer:
The pattern parameter you pass into .requireTextMatchesPattern(pattern) is a Regular Expression and the * character is a RegEx quantifier. If incorrectly used the pattern will be invalid and throws an error.
More Information:
For Regular Expressions, the * character indicates:
Zero or more occurances of the previous element.
For example:
For the expression stacko*verflow the following strings will match:
stackverflow
stackoverflow
stackooverflow
stackoooverflow
stackoooverflow
And so on, provided the string starts with stack and ends with verflow.
In the examples you provided in the above comments, you have the following Regular Expressions:
1:
WvGMkRIQf>|X2ANqg<SGu|j$aN6on**L|v5$N#z7dW!|XU5#5Ml&8Q|Bz%EzuWLiE|a&Cv!IE3E4|-IK4>#ljA8|5ytvZeRJLd|dAOe2L6-g7|P>1UQ<iMYO|yoCZrb7Tom|cuIfBUN%js|FfIq2ASpF0|gZDf8abN1p|mHV>swDHwR|rDgknKK3CS|<$dbw0TfvO|K6xCL&zqk5
2:
hFI*ek0Ypa|>O3eLWaNyI|34UGs*BGWG|4xTlqI5$1v|6J5b4hxhQB|e!UGlGUe!d|RuQgm!07UR|JSe%zMrw84|kEffwcplYp|V#EOUi9xrK|mxxLLZ9rcJ|Z8-PgwizSH|j#lPl3nt3l|q$qzansAMi|<>FOR&yGl2|O0#hIat24N|7DVrI>Oz!5|BgmHjZpoC<|Q53a0cwxw<
3:
mOU-4p%ArY|o>&cL!JMeN
4:
*<R2&$fKfz|x&c&mmNdgT
You can test these for yourself using an online Regular Expression validator but I will explain this here.
In the first example, the culprit is the third string: j$aN6on**L. A double asterisk (**) is not a valid expression as the first asterisk would need to be escaped with a \ (j$aN6on\**L).
The second example does not throw an error as it validates correctly. The same can be said about the third example.
The fourth example also throws an error - this time however it is due to the string starting with the * character. As the * character indicates zero or more occurances of the previous element, but there is no character before the *.
You can check out the basic concepts of Regular Expressions to get a more detailed understanding.
References:
Wikipedia - Regular Expression
Regular Expression - Basic concepts

Unable to Extract Keys have special Characters in MySQL using JSON_EXTRACT

i have a json field in my table(MySQL Database).
the following is the structure:
{
"article":{
"Key's 1":{
"value":"24"
}
"Key's of the something's 2":{
"value":"55"
}
}
}
i am trying to extract the "value" field of "Key's 1".
Due special character such as single quote and space, i am unable use JSON_EXTRACT function.
It give the error: Invalid JSON path expression.This error is around character position no : 10
My Query:
select
JSON_EXTRACT(analytics_json,'$.article.Key\'s 1.value')As value
from
tbl_json_data;
Even after place a backslash, i am getting the error.
You may escape each JSON path component in double quotes to handle special characters as well as spaces. The following works:
SELECT
JSON_EXTRACT(analytics_json,'$.article."Key''s 1".value') AS value
FROM tbl_json_data;
Demo
Note that your key name actually has two problems. First, it contains a literal single quote. We can handle that by just doubling up two single quotes. The key name also contains whitespace. By escaping in double quotes we may workaround this problem, but it would probably be best to avoid using JSON keys which have whitespace.

Best way to escape % before inserting it on MySQL

I am having an issue on inserting this string
input: GyYu4$%acV
posted string: GyYu4$�V
Query error: Incorrect string value: '\xACV' for column.
It seems the best I get is str_replace.
I got the best escape for the issue its about escaping the non-utf8 character that #developerCK mentioned. its utf8_encode

MsDeploy TextFile provider

We are using MsDeploy with Manifest provider, and declareParamFile and setParamFiles.
We would like to replace the string below in a packaged 'runDeploy.cmd' file:
'SET SrvrName=Dev-ServerName' (w/o the quotes) .
SO the DeclareParam.xml file has param entry as below
<parameter name="DbServer" defaultValue="Prod-Server" >
<parameterEntry kind="textFile" scope="runDeploy\.cmd$" match="Dev-ServerName" />
</parameter>
However, the error that we get is
Parameter entry 'DbServer/2' could not be applied to 'C:\Src\bld\runDeploy.cmd'. Deployment will continue with the original data. Details:
No matches were found for the search string 'Dev-ServerName' (type 'TextFile')."
Not sure what is the issue with the plain text here. I have also tried various regex but did not work. Any hints what is wrong?
Thanks
Yatin
The hyphen in the match Regex expression may be causing an issue. Try the following match Regex instead:
Dev.ServerName
The period represents any character and should match the hyphen.