Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Favorites infavorites:mine
infavorites:1234
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with Search options user 142

Questions on expression testing and manipulation through pattern matching and constructing efficient patterns.

11
votes
The observed behaviour will appear in any expression whose symbolic head has the attribute Flat. Under normal circumstances, with no attributes in play, we see the usual expected behaviour: MatchQ[f …
answered Nov 11 '14 by WReach
16
votes
The compiler does a pretty good job of finding and eliminating common subexpressions. We can leverage that functionality. Starting from the provided expression... $expr = (1/Sqrt[2](Sqrt[((Sqrt[((- …
answered Jul 28 '12 by WReach
4
votes
We can match expressions of the desired form thus: $expr = f[a]@f[b]@f[c]@f[d]; MatchQ[$expr //. f[_]@r_ :> r, _f] (* True *) $expr2 = f[a]@f[b]@g[f[c]@f[z]]@f[d]; MatchQ[$expr2 //. f[_]@r_ :> r, …
answered Sep 24 '12 by WReach
5
votes
The General Case Alas, Cases does not permit multiple replacement rules. But Replace does, although we must take care to 1) create an output list, 2) omit non-matching elements and 3) operate only u …
answered Aug 24 '14 by WReach
12
votes
Here is a method using StringSplit and RegularExpression: StringSplit[systemNames, RegularExpression["(?=[$[:upper:]])"]] (* {{A,A,S,Triangle},{Abelian,Group},{Abort},{Abort,Kernels},{Abort,Prote …
answered Nov 20 '14 by WReach
5
votes
I prefer one of @Mr.Wizard's solutions based on StringCases, but here is a solution using StringSplit: StringSplit["Fe3O4", RegularExpression["(?=[A-Z]|\\d)"]] (* {"Fe", "3", "O", "4"} *) It splits …
answered Aug 28 '14 by WReach
9
votes
I suppose that the set of answers won't be complete without the contribution of a cryptic RegularExpression... $pattern = RegularExpression["\\\\newcommand({([^{}]|(?1))*})(?1)"]; The pattern works …
answered Jul 2 '15 by WReach
16
votes
The behaviour we see here is due to the semantics of the regular expression pattern-matching process. Notionally, the string is scanned from left to right. At each character position, an attempt is …
answered Jan 22 '15 by WReach
2
votes
The string subpattern __ in StartOfLine ~~ __ ~~ "::" will match any characters, including line endings. That is why the first match spanned line boundaries: it was the "shortest" match starting from …
answered Sep 29 '17 by WReach
6
votes
I cannot offer a rigorous answer to this question, but I will offer some thoughts... This question asks whether the set of functions computable using basic patterns and MatchQ is isomorphic to the su …
answered Sep 3 '12 by WReach
2
votes
A simple solution uses Partition and Count: $data = {1,0,2,0,3,0,Null,0,2,4,5,6,7,0}; $runLength = 4; $tolerance = 2; Cases[Partition[$data, $runLength, 1], l_ /; Count[l, 0|Null] <= $tolerance] …
answered Feb 4 '12 by WReach
29
votes
This is not a bug. It is a consequence of the manner in which Pick scans its arguments. The Pick Process The documentation for Pick calls its arguments list, sel and patt. Pick scans the list and …
answered Jun 24 '16 by WReach
5
votes
The results we see are due to a subtle interaction between the Flat attribute of Dot and the outermost-in, left-to-right scanning strategy employed by the pattern matcher. The expression a . b . c . …
answered Jan 24 '16 by WReach
17
votes
There are a number of subtle details at work here. Perhaps the prominent one is that in string expressions, unlike expression patterns, Longest and Shortest do not actually refer to the maximal or mi …
answered Feb 26 '16 by WReach
5
votes
The rules seem to be amenable to a recursive regular expression: extract[s_] := StringCases[s, RegularExpression["b|c|(a(?R)*d)"]] extract["abdcbaacdabbdd"] (* {"abd", "c", "b", "aacdabbdd"} *) Fu …
answered Nov 17 '14 by WReach

15 30 50 per page