4.8 How to obtain list of all occurrences of some function in an expression?

For an example, How to find list of all \(\ln \) functions in this expression?

\[ \ln \left ({| x +1|}\right )+2 x \ln \left (x \right )+\sin \left (x \right ) \]
restart; 
expr:=ln(abs(x+1))+2*x*ln(x)+sin(x); 
tmp := indets(expr,'specfunc(anything,ln)'); 
 
          #   tmp := {ln(x), ln(abs(x + 1))}
 

To pick only \(\ln \) functions which has \(abs\) inside them anywhere, replace the above with

restart; 
expr:=ln(abs(x+1))+2*x*ln(x)+sin(x); 
lis:=indets(expr,'specfunc(anything,ln)'); 
select(Z->has(Z,abs),lis) 
 
          #   tmp := {ln(abs(x + 1))}
 

Or, better alternative to the above is

restart; 
expr:=ln(abs(x+1))+2*x*ln(x)+sin(x); 
indets(expr,'specfunc( satisfies(u->has(u,abs)) ,ln  )'); 
 
          #   tmp := {ln(abs(x + 1))}