I am a new user of SMART 6.3 and plan to use it to organise a network of field observers to collect signs of presence of wolves, lynxes and bears in Croatia. I started to adapt Data Model from sample conservation area since it fits to our needs and actually exceeds them in some parts.
I would like to restrict data entry in some existing and newly created fields with a pattern like for Date and Time field (which would be text field since SMART 6 does not support date and time in one field) in a format “dd.mm.yyyy hh:mm”, or in another field as combination of alphanumeric characters, like JK202204151222 (i.e. two letters followed by year, month, day hour and minute).
Every text field can have Regular Expression Validation, but no info about the use of it.
I searched for the instructions in Technical Training Manual SMART 6 and in this forum about the Regular Expression Validation for attribute creation or modification in Data Model. I found no single mentioning of the term, in either of sources. The common wildcard characters like “?”, “#” or “*” do not work or I did not use them properly. Every help is much appreciated!
Thanks!
Josip
Prof. dr. sc. Josip Kusak VMD
Veterinary biology department
Veterinary faculty
University of Zagreb
Heinzelova 55
HR-10000 Zagreb
CROATIA
This is a great idea. To make this usable we’d probably need to have a list of common RegEx codes so that people could choose from a list without having to learn or copy or paste RegEx codes.
Understanding we have users with various levels of skills and that RegEx is easy to mess up, any other suggestions on how we could make enable this very powerful suggestion without creating a risk that people will make mistakes or get stuck?
Thanks on your consideration!
A list of common RegEx would be great!
Beside this, how about leaving the field open for not-so-common RegEx with test feed-back capability before save?
Hi all!
It seems the application of a list of common RegEx codes will not come very soon. Is it possible to get any instructions about how to use this field? It would be very useful for us and we need it very soon.
Thanks!
Josip
It should be any valid regular expressions will work, we use java coding so any specific implementation would be in the java format, but regular expressions are fairly consistent across all uses, so the typical special characters etc should all work. I tried to dig up a few example off the internet quickly, I haven’t tested all these, but they should work:
^\d{4}-\d{2}-\d{2}$ date in the format nnnn-nn-nn where n is any number , ex: 2022-02-23, it would also allow 9999-99-99 so if you want to enforce valid dates that is more complicated
^\d{2}-\d{2}-\d{2} \d{2}:\d{2}$ would allow things like 2022-04-21 09:30 (note you need the 09:30 and not 9:30 to be valid here
you can see the patters for number of of number above, \d{4} requires 4 numbers, you can specify letters as well with something like [a-zA-Z]{2} to allow any regular letters, either case.
Example:
[a-zA-Z]{2}\d{6}
[a-zA-Z]{2} means two letters \d{6} means 6 digits
If you want only uppercase letters, then:
[A-Z]{2}\d{6}
For other needs, I recommend just searching the internet for something like, “regular expression that matches any number of letters” and you usually get good examples to copy.
Here is a general reference that has more scenarios as well:
One other important thing to note, I don’t believe these regex patterns are enforced in SMART Mobile yet, I will send a reminder, that should probably on the Mobile development teams task list.
Hi all,
The good news is that RegEx is implemented in the latest SMART Mobile ver. 416, but i still cannot figure-out how to get time recorded in the format hh:mm, i.e. hours and minutes like 05:35
Writing \d{2}:\d{2} or ^\d{2}:\d{2}$ in the field, does not work for me.
Explanation:
^- at the beginning
\p{Lu}]{1} - one capital letter
[\p{Ll}\p{Lu}]* - any number of capital or lower case letters. You could remove the \p{Lu} if you want to enforce all the rest to be lower case
[ ] - a space
same thing for word/name #2
example matches:
John Doe
ΣSSabcZfg ÇSabcZfg
JIMMy FalLon
fails to match:
John1 Doe2
John F Kennedy
sam lowercase
Example #2:
Match an id and date stamp like this, ĐŠ202208171157; two capital letters followed by YYYYMMDDHHMM pattern.
^[\p{Lu}]{2}[\d]{12}
Explanation:
^[\p{Lu}]{2} - match two capital letters at the start
[\d]{12} - then 12 digits
example matches:
ĐŠ202208171157
FF123456789012
ZZ999999999999
fails to match:
zz999999999999
ZZ20221311245 (months must have 01, not just 0)
I jumped in the previous conclusion to quickly.
The described RegEx syntax works in desktop SMART 7.5.2, but it did not work in the latest two versions of SMART Mobile for Android.
Also, the syntax for two words with first letter capital, was slightly different from the one in example. The syntax which worked for me in SMART Desktop 7.5.2 was:
Two words with first letter capital, Latin letters accepted:
[\p{Lu}]{1}[\p{Ll}][ ][\p{Lu}]{1}[\p{Ll}]
The presence or absence of “^” sign at the beginning did not make difference. Both variants (with and without “^”) worked on SMART Desktop 7.5.2, and did not work on Mobile for Android 422 and 424.