I'm trying to create a regex or something else that will allow the user to enter: Aa0 Aa0 and do this unlimited times or until field length hits it's max or just once
A - capital letter
a - small letter
0 - number
A regex can be written to validate the text, but an input mask cannot be made for an arbitrary length string. the regex expression would be:
([A-Z][a-z][0-9] )+
assuming that at least one grouping of characters is required; change the + to * to allow empty results.
Is there another field in survey123 that I can use to output what I described?
Using the expression above or other ones that I have does not work and shows the ( ) +/* in the output text
Hi Matt,
the regex was intended to be used in the constraint column as part of a regex() function validating the pattern. See the 'Regular Expressions' subsection in Formulas—Survey123 for ArcGIS | ArcGIS for more information.
regex(., '{A-Z][a-z][0-9]+' ) |
I'm trying to use this, but I don't know what it will allow me to input to make it valid...Or4 doesn't work.
I'm having a little trouble understanding how to formulate it
Never mind I fixed my own problem.
Thank you for your help
Hi Matt,
For more information on regular expressions, I might suggest Regular Expressions - JavaScript | MDN as a reference document; I also use https://regex101.com to test the expressions.
The evaluator '{A-Z][a-z][0-9]+' has an issue - the first brace is a curly brace instead of a square brace. Square braces are used to group sets of characters together - [A-Z] looks for an uppercase letter, [a-z] looks for a lower case letter, [0-9] looks for a numeric digit. The pattern you gave (Aa0 ) indicates that these should be grouped together using (); I also included a space as that was what you typed initially (you could also use \s instead of the space, though that would match other whitespace characters):
([A-Z][a-z][0-9] )
You wanted to match at least 1 and possibly more repetitions of this, the + (or * for 0 or more) is used to repeat a pattern:
([A-Z][a-z][0-9] )+
To ensure that the answer has nothing but this pattern, we should also specify to start the match at the beginning (^) and only finish at the end ($)
^([A-Z][a-z][0-9] )+$
All this makes perfect sense and I do understand more now, but have issue with this:
regex(., ^([A-Z][a-z][0-9] )+$) |
The regular expression evaluator should be in quotes:
regex(., "^([A-Z][a-z][0-9] )+$")