1

I'm trying to exclude files starting with characters ~$ from archiving using the regex.

Example of directory contains files:

  • ~$file01.txt
  • ~$file02.txt
  • file01.txt
  • file02.txt

So, I want find all the files in dir that start with "~$", and I've tried the following regex but files are still not excluded

.*/~[^/]*

What's wrong with this?

It is software that archiving files.
I want to exclude from archiving the filenames starting with ~$.
All files will be archived, only files starting with ~$ will not be.
In this software, there is option to add regular expression to exclude files from archiving.
regular-expressions.info link is part of the software documentation, but I don't know how to write the needed regular expression.
Can you help me, please?

3
  • Please edit your question and add more details. How exactly are you using the regular expression to match the file names? Show the command(s) or code you are using, the actual result/output you get and the expected output.
    – Bodo
    Jul 19, 2022 at 14:34
  • If you want file beginning with ~$, why is the second character set to be anything other than /. Can you try echo ./~\$*?
    – doneal24
    Jul 19, 2022 at 14:39
  • I assume you mean filenames, not file contents. But what you using that regex with?
    – ilkkachu
    Jul 19, 2022 at 14:41

1 Answer 1

0

Good day, As mentioned in the comments it would've been better if you provided more detail, especially on the exact command you're using to achieve this, however, since it's regex-related I think the following would be helpful:

Consider these syntaxes:

(?=subexp)         look-ahead
(?!subexp)         negative look-ahead
(?<=subexp)        look-behind
(?<!subexp)        negative look-behind

So in your case it'd be:

(?<!~\$).*
5
  • Related to more detail, it is software and there is only a text field in which I can enter a regex to exclude necessary files. (?<!~$).* don't work either :(
    – user534378
    Jul 25, 2022 at 13:21
  • Well, it's actually understandable that it wouldn't work since I've only used this in the shell specifically zsh. Could you share the software's name so I'd research a little? If sharing the software's not possible I would totally understand.
    – Sinux
    Jul 25, 2022 at 13:26
  • ALSO, please try this too (?<!~\$).*
    – Sinux
    Jul 25, 2022 at 13:28
  • This ^~\$.* works great. Thank you very much for your help.
    – user534378
    Jul 25, 2022 at 14:42
  • I will update my answer then, you're welcome.
    – Sinux
    Jul 25, 2022 at 21:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .