Complex Regex for password field - swift

Im having a difficulty to assemble as complex as this password validation rules:
Shall be at least 8-20 characters:
Shall have At least one number (0-9)
Shall contain At least one special characters (!,#,#,$,%...etc)
No repetition of single character more than 3 times
No repetition of sequence of characters/numbers more than 2 times.
No sequence of 4 or more characters (e.g. abcd)
No sequence of 4 or more numbers (e.g. 1234)
No sequence of 4 or more keyboard characters (e.g. qwer)
May not have any of the above spelled backwards.
That maximum i could achieve is the below, its not working as expected, could someone advice:
^[A-Za-z0-9\\S+](?=.*[$#$#!%*?&]){8,20}

Related

Special Acronym Finder

I'm compiling an acronyms/abbreviations table for a document. Beyond a simple acronym finder, I would like to find special acronyms that aren't entirely conventional.
Generally I can find acronyms by using <[A-Z]{2,}> in an advanced search. This captures any whole word that is comprised solely of uppercase letters. But I have acronyms that take on other forms too. Beyond an acronym being in the form ABC I have acronyms in this document of other forms.
ABC Generic form, 2 or more uppercase letters
AB&C 1 or more letters preceding and following &
ABC(D) 1 letter in parentheses following 2 or more letters (this only appears twice, so I'm not too worried about it.)
A/C 1 or more letters both preceding and following /
ABC-12 2 or more letters followed by a hyphen and 1 or 2 numbers. This only appears once, so I'm not really worried about it.
In my efforts to create an acronym finder, I've developed this specialized search.
<[A-Z]{1,}[\&\/]*[A-Z]{1,}>
Trying to translate this, I see that this is searching for 1 or more uppercase letters preceding 0 or more of & or / followed by 1 or more uppercase letters. In theory this should find forms 1,2, and 4, but in reality it only finds forms 2 and 4, and not 1. (I'm not as much worried about form 3 as I am form 1, 2, and 4.) I'm stumped at what I need to change. I've tried doing an OR | statement to find one or more form, but Microsoft Word's 'regex' options are different (or appear to be different) from what I generally use.
In summary, my question is what form should my special acronym finder be to find forms 1, 2, and 4 in the table above?
You can use a wildcard Find, where:
Find = <[A-Z][A-Z0-9&()/-]{1,}
Beyond that, for identifying acronyms in parentheses and the text to which they refer, see: https://www.msofficeforums.com/word-vba/42313-acronym-definiton-list-generator.html
See also: https://www.msofficeforums.com/word-vba/19395-acronym-finder-macro-microsoft-word.html

Making a sequence of Unicode characters non-editable

Is there a possibility to combine a couple of Unicode characters so that when gets inserted into text editor it would behave like a single entity? Pretty much like emoji, i.e. 🔤(3 characters combined into one). Ideally if the output behaved like a single character, although from what I learned the only option here is a custom font that would provide such symbols and this is not possible in my case.
For a better context:
I make a plugin for GDocs. I need a special set of numeral symbols - all permutations of 2-3 digits (1, 43, 623 etc.). Up to 3 digits would perfect but 2 are quite ok too. I can't allow user to "break" a sequence, i.e. insert a char in-between digits, or erase one ("12m4" - bad).
The special font would solve my problem - there even is one that looks good, but in GDocs I cannot introduce custom font.
Is there some way to do it? Maybe with the hacky use of non-spacing characters between chars, or maybe some other symbols that could help here but I'm not aware of it?

selecting cases based upon first few characters in spss?

i want to select cases with particular first 3 characters.
for example cases with first 3 characters containing "I22".
the length of whole value can vary. e,g "I228" or "I2279" but they have common first three characters "I22"
i usually use compute variable_name= "I228".
but this is tedious as i have to enter all variation of "I22" e.g "I228", "I229" and so on..
it would be much easier if i can just select cases based upon same first 3 characters
you can use the char.cubstr function to find out what the first three characters are in your string variable. For example:
if char.substr(variable_name,1,3)="I22" keep_this=1.
or:
select cases if char.substr(variable_name,1,3)="I22".

Sed's regex to eliminate a very specific string

Disclaimer:
I have found several examples in this site that address questions/problems similar to mine, though I was unfortunately not able to figure out the modifications that would need to be introduced to fit my needs.
The "Problem":
I have a list of servers (VMs) that have it's UUID embedded as part of the name. I need to get rid of that in order to obtain the "pure/clean" server name. Now, the problem is precisely that: I need to get rid of the UUID (which has a very specific and constant format, more details on this below) and ONLY that, nothing else.
The UUID - as you might already know or have noticed - has a specific and constant format which consists of the following parts:
It starts with a dash (-).
Which is followed by a subset of 8 alphanumeric characters (letters are always lowercase).
Which is followed by a dash (-).
Which is followed by a subset of 4 alphanumeric characters (letters are always lowercase).
Which is followed by a dash (-).
Which is followed by a subset of 4 alphanumeric characters (letters are always lowercase).
Which is followed by a dash (-).
Which is followed by a subset of 4 alphanumeric characters (letters are always lowercase).
Which is followed by a dash (-).
Which is followed by a subset of 12 alphanumeric characters (letters are always lowercase).
Samples of results achieved using "my" """"code"""":
In this case the result is the expected one:
echo PRODSERVER0022-872151c8-1a75-43fb-9b63-e77652931d3f | sed 's/-[a-z0-9]*//g'
PRODSERVER0022
In this case the result is the expected one too:
echo PRODSERVER0022-872151c8-1a75-43fb-9b63-e77652931d3f_OLD | sed 's/-[a-z0-9]*//g'
PRODSERVER0022_OLD
Expected result: PRODSERVER0022-OLD
echo PRODSERVER0022-872151c8-1a75-43fb-9b63-e77652931d3f-OLD | sed 's/-[a-z0-9]*//g'
PRODSERVER0022
Expected result: PRODSERVER00-22
echo PRODSERVER00-22-872151c8-1a75-43fb-9b63-e77652931d3f-old | sed 's/-[a-z0-9]*//g'
PRODSERVER00
I know that, within the sed universe, a . means "any character", while a * means "any number of the preceding character". However, what I would need in this case, as I see it at least, is a way to tell sed to do the replacement only if this specific sequence is present (8 alphanumeric characters [any, but specifically 8, not more, not less]; followed by a dash, then followed by 4 alphanumeric characters [any, but specifically 4, not more, not less], etc..). So, the question would be: Is there a regex construction (or a combination [through piping I guess] of several of them, if it has to be the case) that can achieve the expected results in this case?
Note that: Even though servers may have additional dashes (-) as part of their names, the resulting sub-strings will never consist of 8 characters, neither of 4. They might, however, end up having 12 characters, which, even though would initially match up with the last sub-string in the UUID, it will not be at the end of the string, so we have that to discriminate between these two 12-chars substrings (and also it will not be a problem if there is indeed a regex combination that can get rid of the UUID as a whole).
Try this to match the UUID.
-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}
Embed it in the sed command line in the usual way. As Benjamin W. has said, we need to use extended regular expressiongs.
sed -E 's/-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}//g'

How to fill a field with spaces until a length in Notepad++

I've prepared a macro in Notepad++ to transform a ldif file in a csv file with a few fields. Everything is OK but I have a final problem: I have to have 2 fields with a specific length and in this moment I cannot ensure that length because in the source file they are not coming so
For instance, I generate this line:
12345,namenamename,123456
And I have to ensure that the 2nd and 3rd fields have 30 (filling with spaces at right side) and 9 (filling with zeros at left) characters, so in this case I should generate:
12345,namenamename ,000123456
I haven't found how Notepad++ could match a pattern in order to add spaces/zeros, so I have though in to add 1 space/zero to the proper field and repeat this step so many times as needed to ensure the lengths (this is, 29 and 8, because they cannot come empty) and search with the length in the regex (for instance: \d{1,8} for the third field)
My question is: can I repeat only one step of the macro several times (and the rest of the macro only 1 repetition)?
I've read the wiki related to this point (http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Editing_Configuration_Files#.3CMacros.3E) and I don't found anything neither
If not possible, how could be a good solution? Create another 2 different macros and after execute the main one, execute this new 2 macros several times?
Thanks in advance!
A two pass solution with Notepad++ is possible. Find a pair of characters or two short sequence of characters that never occurs in your data file. I will use =#<= and =>#= here.
First pass, generate or convert the input text into the form 12345,=#<=namenamename______________________________,000000000123456=>#=. Ie add 30 spaces after the name and nine zeroes before the number (underscores used here just to make things clearer).
Second pass, do a regular expression search for =#<=(.{30})_*,0*(\d{9})=>#= and replace with \1,\2.
I have just suggested a similar solution in special timestamp format of csv