Title: perl regex for {8} character string with decimal digits AND letters and nothing else
Tags: regex;string;perl
Question: I'm trying to build a Perl regex that matches an 8 character string that requires a length of exactly 8 consisting of at least one letter A-F (uppercase) AND *at least one decimal digit (0-9)*

I'd like the regex to catch:


A13B4D90
13CF928B 
A2F1C3D5


But not:


1392857
2962219
3945580 
ASFLEAN
-MLQORNA


Right now I have 

[\dA-F]{8} 

and it's allowing all of the above. I don't want fields that are all digits or all letters- only want it to match ones with digits AND letters. 

Thank you!

Comment: Well, can you write regexes for the other conditions as well? After that, we can join them into a single regex.

Here is the accepted answer: You can make use of lookaheads:

```^(?=.*\d)(?=.*[A-F])[\dA-F]{8}$
```

```(?= ... )``` makes sure there's a match ahead before continuing the match of the rest of the pattern,

```(?=.*\d)``` basically makes sure there's a digit matching any number of characters from where the lookahead is, in this case from the start of the pattern.

```(=.*[A-F])``` acts the same way, thus it acts as a check to make sure there's a letter between A and F somewhere ahead after any number of characters.

Comment for this answer: PERFECT. I'll have to do some research on look aheads.
Comment for this answer: Note that `$` (as opposed to `\z`) allows for a trailing newline.
Comment for this answer: @user1694958 Could you please mark my answer as accepted? :) Also, I added a few more detail about the lookaheads.
Comment for this answer: @n0741337 You have put a white space after `13CF928B` which naturally makes the string invalid :)
Comment for this answer: @n0741337, looks like fiddle.re's implementation of Perl-compatible regular expressions, is not in fact Perl-compatible. Jerry's regexp works fine in Perl.
Comment for this answer: @Jerry Your regex doesn't appear to work for `13CF928B` according to regexplanet's [Perl beta](http://fiddle.re/tkyyn) ( or its [Java tester](http://fiddle.re/0keyn) ).  I'm trying to learn from your answer and I'm trying to interpret the results from regexplanet.
Comment for this answer: @Jerry - Thanks for looking!  Now I've learned to pay more attention to the subtle boxes from rexplanet's output as well as my copy/pasting :)
Comment for this answer: Depending on the circumstances, `\d` should be `[0-9]` instead.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:09/13/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<regex><string><perl>', 'Title': 'perl regex for {8} character string with decimal digits AND letters and nothing else', 'ViewCount': 1323, 'id': 18794963, 'user_AboutMe': '', 'user_AccountId': 1873159.0, 'user_DisplayName': 'bw1984', 'user_Reputation': 67.0, 'user_Views': 12.0, 'user_id': 1694958.0}}