Google forms Regular Expressions - forms

i'm creating a survey in google forms and cant find any regular expressions for a pin code entry.
The User is being asked a question and can enter 2 pin codes in two text fields.
I need the Regular expression that contains 4 digits with numbers from 0-9.
Example:
Textbox1: 1234
Textbox2: 4321
Any ideas?

Try \d{4}
Also set your Regular Expression to Matches

[0-9]{4}
This should be your regular expression.
function validate() {
var textField = document.getElementById("textbox1").value;
var regex = /[0-9]{4}/g;
alert("Valid input: " + regex.test(textField));
}
<input type="text" id="textbox1">
<input type="button" onclick="validate()" value="Validate">

Related

Modify vscode snippet by regex: TitleCase and SNAKE_CASE

I have two questions for vscode snippets+regex;
I have a pathname like some-component and I need to generate an output like SomeComponent using vscode snippet.
I need to input sendData and return an string like const sendData = createMessage(SEND_DATA);
How can I do this using regex on vscode snippet?
"${TM_DIRECTORY/(.*)/${1:/pascalcase}/g}" you didn't really provide enough info on how you are getting your pathName, so this is just one possibility, perhaps RELATIVE_FILEPATH` works for you.
"$1 = createMessage(${1/(([^A-Z]+)(\\w*))/${2:/upcase}_${3:/upcase}/});"
split the input sendData into 2 capture groups $2 and $3. Upcase them both in the transform.
"sendData": {
"prefix": "cm",
"body": [
"${TM_DIRECTORY/(.*)/${1:/pascalcase}/}",
// simpler form if ONLY two "words" like "sendData"
"$1 = createMessage(${1/(([^A-Z]+)(\\w*))/${2:/upcase}_${3:/upcase}/});",
// for any number of words, like "sendDataTwoThreeFour" use this:
"$1 = createMessage(${1/([a-z]*)([A-Z][a-z]*)/${1:/upcase}${2:+_}${2:/upcase}/g});"
]
}
${1/([a-z]*)([A-Z][a-z]*)/${1:/upcase}${2:+_}${2:/upcase}/g} get the first word "send" into capture group 1 and the other words like "Data" or "Two", etc. into subsequent matches' capture group 2. [So the g flag at the end is very important.]
Upcase group1. Then if there is a group 2 ${2:+_} add _. Then upcase group2.
The only case this will not work on is send with nothing else. It still prints out the all the text just doesn't upcase send if it is by itself. There is probably a way to include that...
Edit: And here it is:
"$1 = createMessage(${1/([a-z]*)([A-Z][a-z]*)|([a-z]+)/${1:/upcase}${3:/upcase}${2:+_}${2:/upcase}/g});"
now a bare send will be put into group 3 and upcased. For the rest of the matches there will not be a group 3 so ${3:/upcase} returns nothing.

How to append a character while using the conditional statement in sightly?

I need to set the href value depending on the nullity of sling:vanityPath. The hit.properties.sling:vanityPath returns the string value for sling:vanityPath property. I need to append a / before the hit.properties.sling:vanityPath value. Is it possible to do that in the following code or do I have to test it twice, but that comes with code repetition?
<a href="${hit.properties.sling:vanityPath == null? hit.path : hit.properties.sling:vanityPath # extension='html'}"/>
Concatenation or binary operators are not supported in HTL. You can either use prependPath or double test for the slash.
I don't think you can do it in one line. But you can try defining a variable for the concatenated value instead of duplicating code for the a tag. Also, do you have to check for null specifically? can't you just reverse the conditions and check if the value exists?
<sly data-sly-test.concatenatedURL="${['/', hit.properties.sling:vanityPath] # join = ''}"/>
<a href="${hit.properties.sling:vanityPath ? concatenatedURL : hit.path # extension='html'}"/>
You can use # join to concat an array:
<a href="${hit.properties.sling:vanityPath ? ['/', hit.properties.sling:vanityPath] : hit.path # join ='', 'extension='html'}"/>

Why this line stops Sphinx search?

I use sanitizing from example: Barryhunter's
But when I use the line:
$q = preg_replace('/[^\w~\|\(\)\^\$\?"\/=-]+/',' ',trim(strtolower($q)));
then Russian search don't works! Only English.
What the reason? How I should use sanitizing?
This is my piece:
<HTML>
<BODY>
<form action="" method="get">
<input name="q" size="40" value="<?php echo #$_GET['q']; ?>" />
<input type="submit" value="Search" />
</form>
<?php
require ( 'sphinxapi.php' );
$sphinx = new SphinxClient;
$sphinx->SetServer('ununtu', 9312);
$sphinx->open();
$sphinx->SetMatchMode (SPH_MATCH_EXTENDED);
$sphinx->setFieldWeights(array(
'title' => 10,
'content' => 5
));
$sphinx->SetRankingMode(PH_RANK_WORDCOUNT);
$sphinx->SetSortMode(SPH_SORT_RELEVANCE);
$sphinx->setLimits(0, 10, 200);
$sphinx->resetFilters();
$q = isset($_GET['q'])?$_GET['q']:'';
$q = preg_replace('/ OR /',' | ',$q);
// $q = preg_replace('/[^\w~\|\(\)\^\$\?"\/=-]+/',' ',trim(strtolower($q)));
if(isset($_GET['q']) and strlen($_GET['q']) > 1)
{
$result = $sphinx->query($sphinx->escapeString($q), '*');
...
Assuming your input string is utf-encoded you use non-unicode preg_replace. Add 'u' in the end, e.g.:
$q = preg_replace('/[^\w~\|\(\)\^\$\?"\/=-]+/u',' ',trim(strtolower($q)));
Specifically that regex is stripping anything that is not a 'word' char, or a predefined list of syntax/punctuation chars.
The PREG definition of word (the \w ) is
A "word" character is any letter or digit or the underscore character,
that is, any character which can be part of a Perl "word". The
definition of letters and digits is controlled by PCRE's character
tables, and may vary if locale-specific matching is taking place. For
example, in the "fr" (French) locale, some character codes greater
than 128 are used for accented letters, and these are matched by \w.
http://php.net/manual/en/regexp.reference.escape.php
So possibly in English locale (or other western European for example), hence many Russian chars are not considered a word char, and stripped.
(if your pages are in UTF8, then may also need the /u as mentioned by other answer)

RegexKitLite How to convert a PHP regex Expression in objective c

I used this regex expression to search for img src in a string in one on my site.
Now I wan't to use this expression to do the same thing in objective c. How can I do that using RegexKitLite?
This is my expression
/<img.+src=[\'"]([^\'"]+)[\'"].*>/i
#Tim Pietzcker
Your code works great but for example if I try to search img in this string
<p> <img src="http://www.nationalgeographic.it/images/2011/07/29/115624013-20034abf-4d91-40fe-98ab-782f06a9854d.jpg" width="140" align="left" hspace="10">Scoperta in America del Sud la sepoltura pre-incaica di un uomo circondato da coltelli cerimoniali che secondo gli archeologi eseguiva sacrifici umani</p>
I have this result in my array:
matchArray: (
"<img src=\"http://www.nationalgeographic.it/images/2011/07/29/115624013-20034abf-4d91-40fe-98ab-782f06a9854d.jpg\" width=\"140\" align=\"left\" hspace=\"10\">"
)
How can I mod your regex to only get the content of src tag? thank you so much
The / delimiters are throwing you off. Also, you should at least use lazy quantifiers. Try this:
NSString *regexString = #"(?i)<img.+?src=['\"]([^'\"]+)['\"].*?>";
This breaks when filenames contain quotes, by the way. Could that be a problem for you?
A regex that's a bit safer (and that handles quotes well) would be
NSString *regexString = #"(?i)<img[^<>]+?src=(['\"])((?:(?!\\1).)+)\\1[^<>]*>";
However, now the matches filename will be in capture group 2, not 1, so you need to modify any code that uses the filename after the match.

Does Len function only evaluate numerical results?

Why does the following code not output "Error" if the form is submitted with a blank field? Does Len only evaluate numerical values?
<cfif NOT Len(Trim("Form.myField"))>
<cfoutput>Error</cfoutput>
</cfif>
The following also does not evaluate as expected:
<cfif Len(Trim("Form.myField")) IS 0>
<cfoutput>Error</cfoutput>
</cfif>
HTML:
<input type="text" name="myField" value="">
Because it's evaluating the literal string "Form.myField", which is not length 0.
Try: <cfif len(trim(form.myField)) EQ 0>
are you sure you're supposed to pass in the parameter in quotes within the trim function? it may be literally trimming the string "Form.myField"