Thursday, July 28, 2022

[SOLVED] How do I convert regex to grep format

Issue

I'm trying to make what I'm able to match in Notepad++ using Regular Expression, have the ability to be grepped. I want to match email:32characters(a-f0-9):3characters(ANYCHARACTER/SYMBOL)

Here's an example:

[email protected]:999999999999999999999999999999a1:&U,  

So far I've been able to match using regex using:

[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}:[a-f0-9]{32}:

But i'm unsure on how to match the last 3 characters (WHICH CAN BE ANYTHING).

Furthermore, when trying to:

grep "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}:[a-f0-9]{32}:" input.txt > output.txt

Nothing is being outputted to my file which seems strange to me. I am using Cygwin Terminal on Windows to perform these greps.


Solution

Use grep -E or egrep if that is available in your environment.

     -E, --extended-regexp
         Interpret pattern as an extended regular expression (i.e. force grep to behave as egrep).


Answered By - Matt
Answer Checked By - David Goodson (WPSolving Volunteer)