AnyOrder[p1,p2,…]
is a grammar rules pattern object that represents a sequence of elements matching p1, p2, … in any order.
AnyOrder
AnyOrder[p1,p2,…]
is a grammar rules pattern object that represents a sequence of elements matching p1, p2, … in any order.
Details
- AnyOrder appears inside GrammarRules and StringExpression objects.
- AnyOrder can be nested inside and outside FixedOrder, Alternatives, and other grammar rule patterns.
Examples
open all close allBasic Examples (2)
Extract elements of a string, which may appear in any order:
StringCases["abc123 456def", AnyOrder[LetterCharacter.., DigitCharacter..]]Deploy a grammar that allows phrases to appear in any order:
grammar = CloudDeploy[
GrammarRules[{
AnyOrder[
FixedOrder["from", from : GrammarToken["City"]],
FixedOrder["to", to : GrammarToken["Ocean"]]
] :> from -> to
}]
]GrammarApply[grammar, "to the Pacific from Boston"]Applications (1)
Deploy a simple calculator that supports infix, Polish, and reverse Polish notation:
calc = CloudDeploy[
GrammarRules[{GrammarToken["Math"]}, {
"Math" -> GrammarToken["Number"],
"Math" -> AnyOrder[a : GrammarToken["Math"], "+", b : GrammarToken["Math"]] :> a + b,
"Math" -> AnyOrder[a : GrammarToken["Math"], "-", b : GrammarToken["Math"]] :> a - b,
"Math" -> AnyOrder[a : GrammarToken["Math"], "*", b : GrammarToken["Math"]] :> a * b,
"Math" -> AnyOrder[a : GrammarToken["Math"], "/", b : GrammarToken["Math"]] :> a / b
}]
]GrammarApply[calc, "2+3"]GrammarApply[calc, "+ 2 3"]GrammarApply[calc, "2 3 +"]GrammarApply[calc, "2 3 + * 5"]This calculator is not programmed to apply precedence to different operators:
GrammarApply[calc, "2 + 3 * 5", AmbiguityFunction -> All]Properties & Relations (1)
In a grammar, FixedOrder requires a specific order and AnyOrder supports arbitrary order:
grammar = CloudDeploy[
GrammarRules[{
a : FixedOrder["1", "2", "3", "4"] :> {"FixedOrder", a},
a : AnyOrder["1", "2", "3", "4"] :> {"AnyOrder", a}
}]
]Here the input matches the order in the FixedOrder:
GrammarApply[grammar, "1 2 3 4", AmbiguityFunction -> All]The input does not match the order in the FixedOrder:
GrammarApply[grammar, "4 3 2 1", AmbiguityFunction -> All]Related Guides
History
Text
Wolfram Research (2015), AnyOrder, Wolfram Language function, https://reference.wolfram.com/language/ref/AnyOrder.html.
CMS
Wolfram Language. 2015. "AnyOrder." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/AnyOrder.html.
APA
Wolfram Language. (2015). AnyOrder. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AnyOrder.html
BibTeX
@misc{reference.wolfram_2026_anyorder, author="Wolfram Research", title="{AnyOrder}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/AnyOrder.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_anyorder, organization={Wolfram Research}, title={AnyOrder}, year={2015}, url={https://reference.wolfram.com/language/ref/AnyOrder.html}, note=[Accessed: 13-June-2026]}