kyle
kyle

Reputation: 113

Using regular expression?

I have two data testing12334 which can be written as

testing[0-9]*$ 

in regular expression then I have testing33ab_1abckd which I can write as

testing[0-9][a-z][_][0-9][a-z].

I am trying to make one reg exp that works for both. Struggling any insight?

UPDATE: in shell(.ksh)

Upvotes: 1

Views: 55

Answers (2)

tripleee
tripleee

Reputation: 189387

Make the suffix part optional

testing[0-9]*([a-z][_][0-9][a-z]+)?$

In basic regular expressions (e.g. traditional grep and sed), you need to backslash the metacharacters. For extended regular expression syntax (basically grep -E and most everything newer than that, save for Emacs) this should work as-is.

Upvotes: 0

anubhava
anubhava

Reputation: 785146

You can use:

\btesting\w+\b

RegEx Demo

Or in shell you can use equivalent:

grep -E '\btesting[[:alnum:]_]+\b'

Upvotes: 1

Related Questions