I am trying to create a regex to match a string with the following criteria:
Should match:
I tried but didn't get a solution. Can you help me?
If the programming language you are using supports regular expression routines , then the following should suit your needs:
^([A-Z](?1)*[0-9]|[0-9](?1)*[A-Z])+$
visualization Debuggex
Demo on regex101
using regexp to store only letters or just numbers and compare them: (example in javascript)
var str = 'A34DF5'; var result = str.replace(/[^a-z]/gi,'').length == str.replace(/[^0-9]/gi,'').length ;