-4

I'm trying to match alphanumeric with the regex below, but still matched the result that I don't need.

([0-9a-z_]+|[0-9a-z]+)

What I really want to match are

Example:
abc123
abc_123

What I don't want to match are

Example:
abc
123
123_123
abc_abc
Deno
  • 434
  • 4
  • 16

1 Answers1

-1

How about perl solution

> cat alphanum.txt
abc123
abc_123
abc
123
123_123
abc_abc
> perl -ne ' { print if /\b([a-z]+)|_\b/ and /([0-9]+)/ }' alphanum.txt
abc123
abc_123
>

try if this works for you.

stack0114106
  • 8,534
  • 3
  • 13
  • 38