# Regex usage in TSystem::ListLibraries()

**URL:** <https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503>\
**Category:** Newbie\
**Created:** [November 24, 2022, 12:25pm UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503 "2022-11-24T12:25:48Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 28, 2022, 8:46am UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/23 "2022-11-28T08:46:09Z")

</div>

I know. The wildcard mode is kept in the PR. Seems to me that’s wrong We should go to regexp seems to me.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 28, 2022, 4:39pm UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/24 "2022-11-28T16:39:06Z")

</div>

I have simplified the code. See the PR.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 28, 2022, 6:40pm UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/25 "2022-11-28T18:40:36Z")

</div>

Looks like you incorporated my macro … but maybe you could leave the “wildcard” possibility, too … see my [`ListLibraries.cxx`](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/12) source code again.

That said, I have some doubts.  
This is clearly some change that breaks “backward compatibility”, but maybe there are not any people who really rely on it (well, it should explicitly be described in the “release notes”, of course).  
The original source code parses the returned “`libs`” using `" \t\s"` as separators, while my macro considers only `" "` (on the other hand, the [TSystem::GetLibraries](https://root.cern/doc/master/classTSystem.html#ad340f02c58426db03aefc78f73f5cded) description says it returns a space separated list of loaded shared libraries, so I don’t understand why / when another separators need to be considered and what is “`\s`”).  
The original source code thinks there can be “`-lNameOfLib`” (it will remove the leading “`-l`”), and it will completely skip “`-Lpathname`” (actually, anything that begins with a “`-`”, except “`-l`”), while my macro doesn’t care.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 29, 2022, 9:14am UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/26 "2022-11-29T09:14:22Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> Looks like you incorporated my macro

Yes, I mentioned you in the PR log.

> [@Wile\_E\_Coyote](#):
>
> but maybe you could leave the “wildcard” possibility, too … see my [`ListLibraries.cxx`](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/12) source code again.

I thought of it but as wildcards do not work because of “/”, is it not simpler to have only regular expression? The way it is done now only changes `ListLibraries`internal code which only parses the RegExp and displays the libs satisfying it. Is that not what is requested from that simple utility?

Calling sequences are not modified so it is much less intrusive. Also, I added a clear example in the method doc.

I checked in the ROOT code and in roottest: `ListLibraries` is not used in any tests. So there will be no issue like comparing the new output to a reference one.

Note also that I did not keep the header and footer of the listing. That did not bring any interesting information and would only make the parsing by a program more difficult.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 29, 2022, 9:21am UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/27 "2022-11-29T09:21:43Z")

</div>

I’ve been thinking about the “wildcard” possibility because someone might already be using such strings with an “appropriate” number of “/” characters inside (and the required changes in the macro were trivial).

BTW. I don’t really understand why you people do it. Whatever I “propose” / commit" is done anonymously (otherwise, I would have created my own pull requests, wouldn’t I). Well, short / simple pieces of code (let’s say up to something like several tens of lines) could be “CC CC0”, and longer / complicated pieces of code could be “CC BY”.

> [@couet](#):
>
> Yes, I mentioned you in the PR log.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 29, 2022, 9:42am UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/28 "2022-11-29T09:42:35Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> I’ve been thinking about the “wildcard” possibility because someone might already be using such strings with an “appropriate” number of “/” characters inside (and the required changes in the macro were trivial).

Seems to me the list libraries always contains `/` in libraries’ names. A wildcard with ‘/’ does not work. Or at least I did not find a simple way to make it work. Did you ?  
The regular expression on the opposite works nicely as it should. So why not simply use working code instead of something which works only when you list all the libraries (which I think 99% of the 0.1% of people using this functionality are doing).

> [@Wile\_E\_Coyote](#):
>
> BTW. I don’t really understand why you people do it. Whatever I “propose” / commit" is done anonymously (otherwise, I would have created my own pull requests, wouldn’t I):

Because that’s the proper way to behave when you use (or get some inspiration from) code written by somebody else.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 29, 2022, 9:54am UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/29 "2022-11-29T09:54:35Z")

</div>

In the case of “wildcards”, you need to use an appropriate number of “`/*`” substrings (yes, it’s a pain, but maybe someone really wants to make sure that some library comes from some precisely defined directory).  
For your example, in one of the previous posts, you would need:  
`root -l -q 'ListLibraries.cxx("/*/*/*/*/*/*Core*", kTRUE)'`

> [@couet](#):
>
> Because that’s the proper way to behave when you use (or get some inspiration from) code written by somebody else.

Well, short / simple pieces of code (let’s say up to something like several tens of lines) could be “CC CC0”, and longer / complicated pieces of code could be “CC BY” → [Wikipedia → Creative Commons license](https://en.wikipedia.org/wiki/Creative_Commons_license)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 29, 2022, 10:31am UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/30 "2022-11-29T10:31:51Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> root -l -q 'ListLibraries.cxx(“/_/_/_/_/\*/_Core_”, kTRUE);f course

Ok, but that’s a real pain, isn’t it ? plus this solution requires to add an extra parameter, and then the help will need to explain the diffrence between wilcard and regexp. Are we sure we want a such complexity for a such simple fonctionnality ?

Of course one other track will be to understand why ‘/’ are special in wilcard.  
I’ll check.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 29, 2022, 11:12am UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/31 "2022-11-29T11:12:16Z")

</div>

> [@couet](#):
>
> Of course one other track will be to understand why ‘/’ are special in wilcard.

That’s actually explained: [TRegexp::MakeWildcard](https://root.cern/doc/master/classTRegexp.html#ab2762d059ace7f79a45b76b0f3b1a1b1)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 29, 2022, 12:14pm UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/32 "2022-11-29T12:14:18Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> That’s actually explained: [TRegexp::MakeWildcard](https://root.cern/doc/master/classTRegexp.html#ab2762d059ace7f79a45b76b0f3b1a1b1)

I know, but that’s not really convincing.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 30, 2022, 11:00am UTC](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503/33 "2022-11-30T11:00:52Z")

</div>

The new version of ListLibraries has been approved. I will merge the PR. Thanks, @abelloni to have seen the problem and @Wile_E_Coyote for your help.

> <https://github.com/root-project/root/pull/11776>
>
> As mentioned \[here\](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibr…aries/52503), it is difficult to list libraries using regular expressions. The \`regexp\` parameter is in fact a wildcard that does not work when the libraries names contain \`/\` (see the help of \[TRegexp::MakeWildcard\](https://root.cern/doc/master/classTRegexp.html#ab2762d059ace7f79a45b76b0f3b1a1b1). An additional optional parameter allows to use the \`regexp\` parameter as a simple string. Only the libraries containing this character string will be listed.
> Example:
> \`\`\`
> root \[0\] gSystem-\>ListLibraries("Core")
>  
> Loaded shared libraries
> =======================
> \-----------------------
> 0 libraries loaded
> =======================
> 
> 
> root \[1\] gSystem-\>ListLibraries("Core",kFALSE)
>  
> Loaded shared libraries
> =======================
> /Users/couet/git/couet-root-bin/lib/libCore.so
> /Users/couet/git/couet-root-bin/lib/libMathCore.so
> \-----------------------
> 2 libraries loaded
> =======================
> \`\`\`

[Previous page](https://root-forum.cern.ch/t/regex-usage-in-tsystem-listlibraries/52503.md?page=1)
