UKC

RegEx question

New Topic
This topic has been archived, and won't accept reply postings.
 ThunderCat 05 Aug 2016

Looking for a regex solution to check an entry on a userform is four alphanumeric characters. Any combination is allowed except 1234

So I got as far as the "^[A-Z0-9]{4}$" and then numerous tweaks to exclude the 1234 combination have failed.

Can anyone help?

It's within Excel VBA, if that's relevant.


Edited: Actually it's only numeric characters, so maybe a little easier....


Post edited at 14:49
 Mike-W-99 05 Aug 2016
In reply to ThunderCat:

Not fully tested but at a glance seemed to work -
^(?!1234)[a-zA-Z0-9]{4}$
OP ThunderCat 05 Aug 2016
In reply to Mike-W-99:

> Not fully tested but at a glance seemed to work -

> ^(?!1234)[a-zA-Z0-9]{4}$

Seems to fit the bill Mike - I really appreciate that!
 Mike-W-99 05 Aug 2016
In reply to ThunderCat:

I hadn't noticed you wanted it for VBA. Amazed it worked!
In reply to ThunderCat:
FYI: This is a great tool for testing RegEx's - https://regex101.com/

The explanation section on the right that breaks the RegEx down into the different matches is a great help when tweaking.
Post edited at 16:38
 lithos 05 Aug 2016
In reply to Mike-W-99:
cool little tester there Paul !

this is a little clearer given your numeric reqs.

^(?!1234)d{4}$
Post edited at 17:35
Clauso 05 Aug 2016
In reply to ThunderCat:

I read your thread title and initially assumed that it was a query about previous partners of Elton John.
OP ThunderCat 05 Aug 2016
In reply to Clauso:

> I read your thread title and initially assumed that it was a query about previous partners of Elton John.

You don't appreciate how my brain works. I've just felt a permanent connection form inside my head. I won't be able to undo the association between regular expressions and reginald dwights previous conquests.

Argh.
1
 Big Ger 06 Aug 2016
In reply to ThunderCat:

> Looking for a regex solution to check an entry on a userform is four alphanumeric characters. Any combination is allowed except 1234

> So I got as far as the "^[A-Z0-9]{4}$" and then numerous tweaks to exclude the 1234 combination have failed.

> Can anyone help?

> It's within Excel VBA, if that's relevant.

> Edited: Actually it's only numeric characters, so maybe a little easier....

Do you have an English translation for this gibberish?



In reply to Big Ger:

> Do you have an English translation for this gibberish?

To be honest, that's not far from my reaction the first time I encountered Regular Expressions
OP ThunderCat 06 Aug 2016
In reply to Big Ger:

> Do you have an English translation for this gibberish?

>
This is a simple example. You should see some of the really difficult stuff...
interdit 06 Aug 2016
In reply to Big Ger:

> Do you have an English translation for this gibberish?

:%s/<gw*h>?/cool stuff/g


New Topic
This topic has been archived, and won't accept reply postings.
Loading Notifications...