Reputation: 419
I have tried following regex.
(?i)(^t|^d|^i|)\S{5}.*
- This matches any string regardless of starting char.(?i)^(t|d|i|)\S{5}.*
- This matches only the one which start with char "t"(?i)[tdi]\S{5}.*
- This looks good but unable to use ^ as this just negate. If i use ^
inside (?i)[^tdi]\S{5}.*
then it matches everything except one which start with t
. I want to match txxxxx
but not xtxxxx
and same is the case for i
and d
.What is correct regex to achieve it?
First, string must start with one of these char specified and then must follow minimum 5 char (no whitespace) char and then it can have anything behind, i.e txxxxx.domain.local
, dxxxxx.domain.local
but at the same time it should not match with xtxxxx.domain.local
or xdxxxx.domain.local
.
Upvotes: 1
Views: 110
Reputation: 627292
In general, if you need to match any word that consists of letters, digits or underscors starting with a specific letter you may use
(?i)\b[tdi]\w*
It will match t
, T
, d
, D
, I
or i
at a word boundary (\b
) and then any 0 or more letters, digits or underscores.
You may use
(?i)(?<!\S)[tdi]\S{5,}
See the regex demo
(?i)
- case insensitive modifier on(?<!\S)
- whitespace should come right before the match[tdi]
- one of the three letters that the word should start with\S{5,}
- five or more non-whitespace chars.Upvotes: 1