I'm trying to match a string in my files which begins with imports: [
and does not contain SharedModule
. It can have any number or spaces, line-breaks, or other characters (words) in between the two strings. I've been trying to do find those with:
grep 'imports: \[[.*\s*]*SharedModule' */*.module.ts
but I cannot even find the files which have 'SharedModule' in it. My thought process was that .* would find any words and \s would find blank space characters, and the character class with * selector would allow this to show up in any order.
- Can I use character classes like this to skip a variable number of unrelated lines/characters?
- How do I negate the statement so it returns lines without 'SharedModule'?
- The goal is to append 'SharedModule' to the import array wherever it does not already exist.
Thanks! (I'm new to this and the one thing I've learned so far is: regular expressions are hard)
SAMPLE MATCH:
imports: [
IonicPageModule.forChild(FormPage),
DynamicFormComponentModule,
SharedModule
],
should not match but
imports: [
IonicPageModule.forChild(LeadershipPage),
],
should.