Assume i have a big paragraph, in which there are words are like found
field
failed
fired
killed
(so many negative words i know!!)
Now, I want to fetch line which have words starting from fi
hi
or k
and ends with eld
or ed
How would i go about searching this pattern of word in string....??
keep in check that i am asking about word pattern in string, not string pattern
These 2 surely didn't worked
egrep "^(f[ai]|k)+(eld|ed)$"
and
egrep "\<(f|k)+(eld|ed)$\>"
I'll admit i am not a hulk of regex
, doing it out of basic understanding, so any one willing to suggest a better way (with some description) is most welcome too!! :)
The regex you are probably looking for would be
"\b([fh]i|k)\w*(eld|ed)\b"
The \w*
should be equivalent to [a-zA-Z0-9_]*
, so that will allow any word-like characters be between requested strings.
The \b
is there to ensure, that the word really starts and ends with letters you want. Otherwise you might for example match string which contains word Unfailed
Also you need to remove $
and ^
from the regex because $
means end of line and ^
the beginning of line.