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
Related
Some confusion here where I have to use filebeat multiline pattern to collec data.
Question is how to use multiple pattern ?
Here what i use now
multiline.pattern : '^Select'
So for above pattern we can see all word start from select will be match. So my question how about INSERT,UPDATE and DELETE word ?
Also one question can I use below pattern to indicate end of multiline match ?
multiline.flush_pattern: ';'
Any idea or help is highly appreciated
To your first question:
You can specify multiple words for the beginning of the message within a single regex. So if I understood you correctly, you want to include all log lines that start with Select, INSERT, UPDATE and DELETE. To achieve this you would define a group of valid values like so:
multiline.pattern : '^(Select|INSERT|UPDATE|DELETE)
The pipe-character ( | ) acts as an OR-Operator. Please note that by default regex is case sensitive. So e.g. messages that start with an uppercase SELECT would be ignored in the sample above.
To your second question:
Besides multiline.pattern you have to specify the settings multiline.match and multiline.negate:
multiline.match determines if the log lines before or after the pattern should be put into a single event.
multiline.negate determines if the following lines have to match the pattern.
So instead of specifying a particular end-character you tell Filebeat that every log line that matches the pattern AND is following that line should get aggregated UNTIL the following line matches again the pattern.
(See https://www.elastic.co/guide/en/beats/filebeat/current/multiline-examples.html for a full reference and description).
Example:
Assuming your log file is structured as following:
Select foo from bar\n where baz = 1\n and id =4711;\n\n
DELETE from bar\n where baz = null;\n\n
INSERT ...
the following config should do the job:
multiline.pattern : '^(Select|INSERT|UPDATE|DELETE)'
multiline.match: after
multiline.negate: true
I hope I could help you.
I'm writing a test case in robot framework. I'm getting the response in below json string:
{"responseTimeStamp":"1970-01-01T05:30:00",
"statusCode":"200",
"statusMsg":"200",
"_object":{"id":"TS82",
"name":"newgroup",
"desc":"ttesteste",
"parentGroups":[],
"childGroups":[],
"devices":null,
"mos":null,
"groupConfigRules" {
"version":null,
"ruleContents":null
},
"applications":null,"type":0
}
}
From that I want to take "_object" using:
${reqresstr} = ${response['_object']}
... but am getting the error "No keyword with name '=' found" error
If I try the following:
${reqresstr}= ${response['_object']}
... I'm getting the error "Keyword name cannot be empty." I tried removing the '=' but still get the same error.
How can I extract '_object' from that json string?
When using the "=" for variable assignment with the space-separated format, you must make sure you have no more than a single space before the "=". Your first example shows that you've got more than one space on either side of the "=". You must have only a single space before the = and two or more after, or robot will think the spaces are a separator between a keyword and argument.
For the "keyword must not be empty" error, the first cell after a variable name must be a keyword. Unlike traditional programming languages, you cannot directly assign a string to a variable.
To set a variable to a string you need to use the Set Variable keyword (or one of the variations such as Set Test Variable). For example:
${reqresstr}= Set variable ${response['_object']}
${reqresstr}= '${response["_object"]}'
wrap it inside quotes and two spaces after =
There is a syntax error in your command. Make sure there is a space between ${reqresstr} and =.
Using your example above:
${reqresstr} = ${response['_object']}
not sure how far I'm going to get with this, but I'm going through a database removing certain bits and pieces in preparation for a conversion to different software.
I'm struggling with the image tags as on the site they currently look like
[img:<string>]<image url>[/img:<string>]
those strings are in another field called bbcode_uid
The query I'm running to make the changes so far is
UPDATE phpbb_posts SET post_text = REPLACE(post_text, '[img:]', '');
So my actual question, is there any way of pulling in each string from bbcode_uid inside of that SQL query so that I don't have to run the same command 10,000+ times, changing the unique string every time.
Alternatively could I include something inside [img:] to also include the next 8 characters, whatever they may be, as that is the length of the string that is used.
Hoping to save time with this, otherwise I might have to think of another way of doing it.
As requested.
The text I wish to replace would be
[img:1nynnywx]http://i.imgur.com/Tgfrd3x.jpg[/img:1nynnywx]
I want to end up with just
http://i.imgur.com/Tgfrd3x.jpg
Just removing the code around the URL, however each post_text has a different string which is contained inside bbcode_uid.
Method 1
LIB_MYSQLUDF_PREG
If you want more regular expression power in your database, you can consider using LIB_MYSQLUDF_PREG. This is an open source library of MySQL user functions that imports the PCRE library. LIB_MYSQLUDF_PREG is delivered in source code form only. To use it, you'll need to be able to compile it and install it into your MySQL server. Installing this library does not change MySQL's built-in regex support in any way. It merely makes the following additional functions available:
PREG_CAPTURE extracts a regex match from a string. PREG_POSITION returns the position at which a regular expression matches a string. PREG_REPLACE performs a search-and-replace on a string. PREG_RLIKE tests whether a regex matches a string.
All these functions take a regular expression as their first parameter. This regular expression must be formatted like a Perl regular expression operator. E.g. to test if regex matches the subject case insensitively, you'd use the MySQL code PREG_RLIKE('/regex/i', subject). This is similar to PHP's preg functions, which also require the extra // delimiters for regular expressions inside the PHP string
you can refer this link :github.com/hholzgra/mysql-udf-regexp
Method 2
Use php program, fetch records one by one , use php preg_replace
refer : www.php.net/preg_replace
reference:http://www.online-ebooks.info/article/MySql_Regular_Expression_Replace.html
You might be able to do this with substring_index().
The following will work on your example:
select substring_index(substring_index(post_text, '[/img:', 1), ']', -1)
I have a table of messages. I am trying to find messages in the table that have an ID code which complies with a specific format. The regexp that I have below was written for matching these values in PHP, but I want to move it to a MySQL query.
It is looking for a specific format of an identifier code that looks like this:
[692370613-3CUWU]
The code has a consistent format:
starts and ends with hard brackets [ ]
two components inside,
first is an account number, min 9 digits, but could be higher
second component is a alphanumeric code, 5 characters, can include 1-9, and capital letters excluding "O"
the complete code can occur anywhere in the message
I have a query that reads:
SELECT * FROM messages
WHERE
msgBody REGEXP '\\[(\d){9,}-([A-NP-Z1-9]){5}\\]'
OR
msgSubject REGEXP '\\[(\d){9,}-([A-NP-Z1-9]){5}\\]'
I created a test row in the table which has only the sample value above in the msgBody field for testing - but it does not return any results.
I am guessing that I am missing something in the conversion of PHP style regex vs. MySQL.
Help is greatly appreciated.
Thank you!
Instead of \d try using [[:digit:]]
SELECT * FROM messages
WHERE
msgBody REGEXP '\\[([0-9]){9,}-([A-NP-Z1-9]){5}\\]'
OR
msgSubject REGEXP '\\[([0-9]){9,}-([A-NP-Z1-9]){5}\\]'
Attempting to change the "files" folder location in a Drupal site from /files to /sites/default/files.
In order to avoid changing anything else such as
http://www.google.com/profiles/
I'm trying to use a basic regular expression with a word boundary.
\bfiles/
A quick check in regexpal is working as expected, but when I enter the above in the phpMyAdmin search , checking the "as regular expression" checkbox, I don't get the expected result.
Two questions:
How should I write my expression with a word boundary so that it works in phpMyAdmin?
I'm really a newbie at SQL statements! Would it be possible to write a SQL query that would simply look for every occurrence of "files/" & replace it with "sites/default/files/"?
According to the MySql docs, the regex flavour used is POSIX 1003.2. For this flavour of regex, word boundaries are as follows:
[[:<:]] (beginning) [[:>:]] (end)
so your regex would be:
[[:<:]]files/
If you want to use sql to search and replace all instances of [[:<:]]files/ from a specific field in a table, you could use a UDF such as the one found here
Also, you should be aware of the following while using regex with MySql:
Because MySQL uses the C escape syntax in strings (for example, ā\nā
to represent the newline character), you must double any ā\ā that you
use in your REGEXP strings.