Regex code for any string containing BOTH letters AND digits and possibly underscores and dashes
ms-word, regex
Solution
You can use the following expression with the case-insensitive mode:
\b((?:[a-z]+\S*\d+|\d\S*[a-z]+)[a-z\d_-]*)\b
Explanation:
\b # Assert position at a word boundary
( # Beginning of capturing group 1
(?: # Beginning of the non-capturing group
[a-z]+\S*\d+ # Match letters followed by numbers
| # OR
\d+\S*[a-z]+ # Match numbers followed by letters
) # End of the group
[a-z\d_-]* # Match letter, digit, '_', or '-' 0 or more times
) # End of capturing group 1
\b # Assert position at a word boundary
Regex101 Demo
Problem
My regex knowledge is pretty limited, but I'm trying to write/find an expression that will capture the following string types in a document: DO match: - ADY123 - AD12ADY - 1HGER_2 - 145-DE-FR2 - Bicycle1 - 2Bicycle - 128D - 128878P DON'T match: - BICYCLE - 183-329-193 - 3123123 Is such an expression possible? Basically, it should find any string containing letters AND digits, regardless of whether the string contains a dash or underscore. I can find the first two using the following two regex: - /([A-Z][0-9])\w+/g - /([0-9][A-Z)\w+/g But searching for possible dashes and hyphens makes it more complicated... Thanks for any help you can provide! :) MORE INFO: I've made slight progress with: ([A-Z|a-z][0-9]+-*_*\w+) but it doesn't capture strings with more than one hyphen. I had a document with a lot of text strings and number strings, which I don't want to capture. What I do want is any product code, which could be any length string with or without hyphens and underscores but will always include at least one digit and at least one letter.