2

Trying to build a regular expression that will match all strings that begin with word "med-" and end with ".opol.nei.com" like this one

med-fe3-ua-kiol-33.opol.nei.com

2 Answers2

2

perl, sed, grep:

med-.*.opol.nei.com

bash expansion:

med-*.opol.nei.com
Wayne_Yux
  • 4,873
2

Wayne Yux answer might match more than what is intended. med-.*.opol.nei.com will match any character instead of the dots.

For example: med-abcXopolYneiZcom will match the regex above.

To be more specific the dots should be escaped like this: med-.*\.opol\.nei\.com. Here the dot is interpreted as a dot only.

To Do
  • 15,502
  • add a $ at the end of the regex, it match something like med-ecbv.opol.nei.comTEST if not (using grep "med-.*\.opol\.nei\.com$" command) – damadam Nov 21 '19 at 11:06
  • 1
    also, there is the ^ for matching the begenning, it match Amed-ecbv.opol.nei.com if not ( using grep "^med-.*\.opol\.nei\.com$" command) – damadam Nov 21 '19 at 11:13