14 votes

Position and string patterns

For large lists, this should be snappy: Pick[Range@Length@dat, StringTake[dat, UpTo@4], "star"] and actually, taking advantage of listability, ...
  • 25.2k
13 votes
Accepted

Position and string patterns

Position[dat, _String?(StringMatchQ[#, "star" ~~ ___] &)] or Position[dat, _String?(StringMatchQ[#, "star*"] &)] or ...
  • 351k
12 votes
Accepted

Is there a built-in function to do binary search?

There is some built-in binary search code but not in the core language as far as I know. There is BinarySearch from the Combinatorica package, which is still the ...
  • 265k
12 votes
Accepted

Searching a phrase in all *.nb files

Here is a way to search from within mathematica: ...
  • 38.4k
12 votes

Implementing a Better Grep Command

Mathematica allows text searching using regular expressions (based on the PCRE library). It would take some work to re-implement the whole grep functionality within ...
11 votes
Accepted

Searching for an unordered triple in a list of triples

This seems to be a case for OrderlessPatternSequence tT = {{7, 1, 2}, {7, 2, 3}, {7, 3, 8}, {7, 1, 6}}; MemberQ[tT, {OrderlessPatternSequence[1, 2, 7]}] True ...
  • 351k
10 votes
Accepted

Determine if a variable appears in an expression or not?

The functions you are looking for are MemberQ and FreeQ. Both functions take a levelspec and the Option ...
  • 265k
10 votes
Accepted

Find file names in directory

All three of parameters for FileNames can affect the depth at which Mathematica searches for results. It seems like your confusion is a result of interaction among ...
  • 8,392
10 votes

How can I implement my own documentation search function?

Update This code is no longer the most up-to-date. The properly up-to-date code is in the package on GitHub. For a run-down of the changes between this and that see the discussion between b3m2a1 and ...
  • 45.8k
9 votes

Finding all of the words containing certain letters

DictionaryLookup for each case, combined with string patterns involving ___ can be very slow. It would be faster to do it in one ...
  • 87.2k
9 votes

Basic Search Functionality

...
9 votes
Accepted

Basic Search Functionality

As of Mathematica 11: ...
  • 69k
9 votes
Accepted

Working with deep lists

If there is no particular reason for using Outer, then this is simple and straightforward: ...
  • 23.3k
9 votes
Accepted

How to cache results of WebImageSearch?

So it looks like the only real way to do this is by hacking the mainframe package that underlies this. Everything seems to be clumsy and hard coded, so I had to dig a little. The following works for ...
  • 45.8k
8 votes
Accepted

Extracting values with multiple keys

In response to a), you can write Merge[Rule @@@ data, Identity], which is slightly simpler. In response to b), there are two different ways to do this nicely. One ...
8 votes

How can I get Google search results with Mathematica?

Mathematica now supports a native connection to GoogleCustomSearch API. You can do for example ...
  • 998
8 votes
Accepted

Searching for literal strings with TextSearch

I'd say that the acceptable forms of the query string are much more limited than the documentation lets on. In fairness though, TextSearch is marked [[Experimental]]...
  • 63k
8 votes
Accepted

Find elements of array with largest absolute value

You could use SparseArray to do this: ...
  • 125k
8 votes
Accepted

Solving a rotating combination lock puzzle

I'd implement backtracking like this: ...
  • 69k
7 votes

Why does documentation search fail on substrings?

In the Wolfram Language Documentation Center from the menu Help > Wolfram Documentation, I use wild card characters to broaden the search. For example CreateDoc*. ...
  • 14.9k
7 votes
Accepted

Finding all of the words containing certain letters

I think you'll find this considerably faster... Intersection @@ (DictionaryLookup["*" <> # <> "*"] & /@Characters["aeiouy"]) and getting sneaky ...
7 votes

Searching a phrase in all *.nb files

Note: the following method isn't robust. See this answer of mine for a robust solution. Here is an approach which does not rely on the NBImport.exe (which actually performs importing of the NB files ...
7 votes

Searching a phrase in all *.nb files

A couple of additional solutions. The first, with FindList, is probably the simplest and quickest. Using FindList ...
7 votes

Working with deep lists

corey979's answer is simple and elegant for small numbers of values of x, a, and b. But if ...
7 votes
Accepted

Find sublists in a list by contents, then union them

Using rules: groups //. {a___, x : {___, b | g, ___}, b___, y : {___, b | g, ___}, c___} :> {a, Union[x, y], b, c} This behaves differently compared to your ...
  • 69k
7 votes

Find sublists in a list by contents, then union them

Flatten /@ Gather[groups, MemberQ[#1, b | g] && MemberQ[#2, b | g] &]
  • 21.7k
7 votes
Accepted

Find permutation index

I think you'll find this considerably more efficient than the accepted answer: ...
  • 25.2k
7 votes

Implementing a Better Grep Command

Update As recommended in the comments by @b3m2a1, you can also use RunProcess as a simpler way to execute grep. You need to ...
  • 16k
7 votes
Accepted

How to test if $ⅈ$ is in an expression?

Look at the FullForm. This is what Mathematica actually sees. ...
  • 45.8k
7 votes
Accepted

Faster searching for subsets with pairwise conditions

Might be faster to cull as you go. I compile the selection function (possibly it can be made faster). Also I set the history length to zero although that does not help too much because the ...

Only top scored, non community-wiki answers of a minimum length are eligible