Reputation: 125
I am trying to create a regex to match a string with the following criterion:
Should match:
I tried, but didn't get a solution. Can you help me out?
Upvotes: 3
Views: 130
Reputation: 48817
If the programming language you're using supports regex subroutines, then the following one should suit your needs:
^([A-Z](?1)*[0-9]|[0-9](?1)*[A-Z])+$
Visualization by Debuggex
Demo on regex101
Upvotes: 4
Reputation: 361
using regexp to keep only letters or only numbers and comparing them : (example in javascript)
var str = 'A34DF5';
var result = str.replace(/[^a-z]/gi,'').length == str.replace(/[^0-9]/gi,'').length ;
Upvotes: 2