Ad Widget

Collapse

Regexp with more than one word that have to match in same line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WrongError
    Junior Member
    • Jan 2025
    • 2

    #1

    Regexp with more than one word that have to match in same line

    Hello everybody,

    I want to search after more than one word in a text line/row in a logfile with regexp. I tried "(?=.*Word1)(?=.*Word2)" already but its not working correctly. Even if only one word is written correctly in the specific line the line is getting printed. It should only show this line if both words are perfectly matching.
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4806

    #2
    Can you give any real world examples, what needs to be matched and what not.. Your current lookahead construct does not make any sense...

    Comment

    • Blevar
      Member
      • Jan 2025
      • 68

      #3
      You are looking for a line which must contain both words? Try: (
      Code:
      ?=.*\bWord1\b)(?=.*\bWord2\b).*

      Comment

      • troffasky
        Senior Member
        • Jul 2008
        • 565

        #4
        regex101.com is an excellent tool for helping with writing regexen.

        Comment

        Working...