0

I have a problem to solve:

I need to match every word which has less than 4 characters expect word i,j,k and pom.I made reg exp which finds all words where the size is less than 4 - [a-zA-Z]{1,3} but i dont know how to exclude i,j,k and pom. And i need to do it in one reg exp.

Thanks a lot for the answers

anticol
  • 487
  • 1
  • 4
  • 12
  • 1
    Please add sample input and your desired output for that sample input to your question. – Cyrus Feb 26 '17 at 19:47
  • @SLePort he means characters i and j and k should pass the regex, while they are less than 4. – behkod Feb 26 '17 at 21:45
  • Input: int i = 5; int pom = 1; char var = 'a'; int hello = 0; bool hey = true; And output should be (what should reg exp match is): char var = 'a'; bool hey = true; – anticol Feb 27 '17 at 09:14

2 Answers2

0

Something like this ?

$ cat b.txt
abcdef
abcd
abc
pom.
pom
i,j,k

$ grep -E '^([a-z]{1,3}|pom.|i,j,k)$' b.txt
abc
pom.
pom
i,j,k

Remarks:
* Test above matches lines, you can modify it like -E -w -o to match words in line
* Word pom will be matched by default since it has length three=less than 4
* Word pom. (ending in dot) would have been excluded, but it is saved due to regex or operation (symbol |)

Update

$ grep -E '^([a-z]{1,3}|pom.|i|j|k)$' b.txt
George Vasiliou
  • 6,130
  • 2
  • 20
  • 27
0

updated
(?i)\b(?!pom|[ijk]\b)[a-z]{1,3}\b

 (?i)                     # Inline modifier, case-insensitive
 \b                       # word boundary
 (?! pom | [ijk] \b )     # Assert not 'pom' nor single i, j or k
 [a-z]{1,3}               # 1 to 3 letters a-z
 \b                       # word boundary