0

I mean characters like - _|/\()[]{} or/and others I must forget.

A usecase would be, for instance, and assuming this character is ¤ :

apt-search ¤obs¤

enabling filtering of results such as obsolete observation, etc...

Or more generally X | egrep ¤.

I guess I don't have the good terminology for it, but I was unable to find results online.

3
  • 1
    Which application are you searching an answer for? This question is tagged bash, but the in the example of apt-search ...., it would actually be apt-search doing to regular expression matching.
    – Wieland
    Commented Jan 7, 2020 at 18:07
  • @Wieland, Well I'm looking for the most general solution, so it doesn't matter. apt was simply an example. Just think of apt-search obs | grep ¤ or more generally X | egrep ¤ (or a more efficient way I'm not aware of). I'll modify my answer to reflect the general way.
    – Atralb
    Commented Jan 7, 2020 at 18:15
  • [[:punct:]]+, though it looks no better than enumerating them ;-). But I think that you better use the \< and \> (start/end of word "zero-length assertions") which are supported by apt: apt-cache search '\<obs\>'.
    – user313992
    Commented Jan 7, 2020 at 20:09

2 Answers 2

0

In regex it is [] _|/\()[{}-], just the whole lot between []. However note that ] has to be the first (to stop it being interpreted as the close), and - has to be first or last (to stop it being interpreted as a range).

0

Here, you could use the word boundary operators: either the \b from perl or \<, \> from vi both supported by apt and aptitude.

That matches at the transition between a word character and a non-word character, a word character being an alphanumeric character or underscore in that case. That wouldn't work for you in that you want to consider _ as a separator, but note that Debian packages don't have _ in their name, so that shouldn't be an issue if it's the package name you want to match against.

To search on package name only:

$ aptitude search '~n \bobs\b'
p   obs-api                         - Open Build Service (api)
p   obs-build                       - scripts for building RPM/debian packages f
p   obs-plugins                     - recorder and streamer for live video conte
p   obs-plugins:i386                - recorder and streamer for live video conte
p   obs-plugins-dbgsym              - debug symbols for obs-plugins
p   obs-plugins-dbgsym:i386         - debug symbols for obs-plugins
p   obs-productconverter            - Open Build Service (product definition uti
p   obs-server                      - Open Build Service (server component)
p   obs-studio                      - recorder and streamer for live video conte
p   obs-studio:i386                 - recorder and streamer for live video conte
p   obs-studio-dbgsym               - debug symbols for obs-studio
p   obs-studio-dbgsym:i386          - debug symbols for obs-studio
p   obs-utils                       - Open Build Service (utilities)
v   obs-webui                       -
p   obs-worker                      - Open Build Service (build host component)

Because \b is a word boundary, it also matches at the start of the subject, even though in that case obs is not preceded by a separator character.

You must log in to answer this question.

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