Home > Enterprise >  How to Regex all lines away that do not contain a dot?
How to Regex all lines away that do not contain a dot?

Time:06-27

Right, how do I regex all lines away that do not contain a dot? an example of this would be:

Turning this:

REDACTED/file-20220625/assets/catalogue/otherpetcatalogue.swf
REDACTED/file-20220625/assets/catalogue/petcatalogue.swf
REDACTED/file-20220625/assets/catalogue/pets
REDACTED/file-20220625/assets/catalogue/storytelling
REDACTED/file-20220625/assets/catalogue/coolfile.swf

into this:

REDACTED/file-20220625/assets/catalogue/otherpetcatalogue.swf
REDACTED/file-20220625/assets/catalogue/petcatalogue.swf
REDACTED/file-20220625/assets/catalogue/coolfile.swf

I would really appreciate your help with this, Thanks!

CodePudding user response:

To delete lines that do not contain a dot:

Search: ^[^.]*\n
Replace: <blank>

The regex matches from start of line ^ up to and including the newline with no dots between, so that the operation deletes the whole line.

CodePudding user response:

I'd use ^[^.] $, where:

  • the first hat ^ and the dollar sign $ denote the beginning and end, thus indicating that the rule must be applied to the whole string
  • [^.] means all characters except for the dot (so here the hat ^ means negation: a character that is anything but a dot)
  • the plus sign means that there must be at least one non-dot character. You can replace this with an asterisk * in case you want to accept empty strings as well.
  • Related