<matchesPattern>
<matchesPattern> is an Evaluation
component that returns the boolean value of true or false depending on whether the enclosed
math (often a referenced <mathInput/>) conforms to the specified pattern template.
Attributes and Properties
Attributes for <matchesPattern>
Other (19)
allowedErrorInNumbersnumber. Default value: 0. Maximum allowed numeric error when comparing numbers.
allowedErrorIsAbsoluteboolean. Default value: false. Whether allowedErrorInNumbers is interpreted as an absolute (rather than relative) tolerance.
allowImplicitIdentitiesboolean. Default value: false. Whether to allow implicit identity transformations when matching.
allowPermutationsboolean. Default value: true. Whether to allow permutations of operands when matching.
caseInsensitiveMatchboolean. Default value: false. Whether text comparisons ignore letter case.
excludeMatchesmathList. Patterns whose matches are excluded.
expandOnCompareboolean. Default value: false. Whether to expand math expressions before comparing.
includeErrorInNumberExponentsboolean. Default value: false. Whether the allowed numeric error also applies to numbers in exponents.
matchBlanksboolean. Default value: false. Whether unfilled blanks in a math expression count as a match.
matchByExactPositionsboolean. Default value: false. Whether to match list values by exact position rather than by content.
matchExpressionWithBlanksboolean. Default value: false. Whether to allow expressions with blanks to match.
numPeriodicSetMatchesRequiredinteger. Default value: 3. Number of consecutive elements of a periodic set required to count as a match.
numSignErrorsMatchednumber. Default value: 0. Maximum number of sign errors that still count as a match.
patternmath. Math expression pattern to match against.
requireNumericMatchesboolean. Default value: false. Whether numeric placeholders must match numbers.
requireVariableMatchesboolean. Default value: false. Whether variable placeholders must match variables.
simplifyOnComparekeyword. Level of simplification applied to math expressions before comparing.
| Value | Description |
|---|---|
none (default) | No simplification is applied before comparing. |
full | Fully simplify both expressions before comparing. |
numbers | Simplify numeric subexpressions only, leaving symbolic structure intact. |
numbersPreserveOrder | Like numbers, but does not reorder commutative operands. |
normalizeOrder | Reorder commutative operands into a canonical form without simplifying values. |
symbolicEqualityboolean. Default value: false. Whether children compared via this boolean use symbolic equality.
unorderedCompareboolean. Default value: false. Whether order is ignored when comparing list-like values.
Common to all components (9)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedboolean. Default value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. Default value: 1. The style number used to select this component's visual styling from the available style definitions.
Properties for <matchesPattern name="m">
Other (26)
$m.allowedErrorInNumbersnumber. Maximum allowed numeric error when comparing numbers.
$m.allowedErrorIsAbsoluteboolean. Whether allowedErrorInNumbers is interpreted as an absolute (rather than relative) tolerance.
$m.allowImplicitIdentitiesboolean. Whether to allow implicit identity transformations when matching.
$m.allowPermutationsboolean. Whether to allow permutations of operands when matching.
$m.caseInsensitiveMatchboolean. Whether text comparisons ignore letter case.
$m.disabledboolean. Whether this component is disabled and cannot be interacted with.
$m.excludeMatchesmathList. Patterns whose matches are excluded.
$m.expandOnCompareboolean. Whether to expand math expressions before comparing.
$m.fixedboolean. Whether this component's value is fixed and cannot be modified.
$m.fixLocationboolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
$m.includeErrorInNumberExponentsboolean. Whether the allowed numeric error also applies to numbers in exponents.
$m.matchBlanksboolean. Whether unfilled blanks in a math expression count as a match.
$m.matchByExactPositionsboolean. Whether to match list values by exact position rather than by content.
$m.matchExpressionWithBlanksboolean. Whether to allow expressions with blanks to match.
$m.numMatchesnumber. The number of matches found.
$m.numPeriodicSetMatchesRequiredinteger. Number of consecutive elements of a periodic set required to count as a match.
$m.numSignErrorsMatchednumber. Maximum number of sign errors that still count as a match.
$m.patternMatches[ math ]. The list of matched sub-expressions.
$m.requireNumericMatchesboolean. Whether numeric placeholders must match numbers.
$m.requireVariableMatchesboolean. Whether variable placeholders must match variables.
$m.simplifyOnComparetext. Level of simplification applied to math expressions before comparing.
$m.symbolicEqualityboolean. Whether children compared via this boolean use symbolic equality.
$m.texttext. The boolean rendered as a text string ("true" or "false").
$m.unorderedCompareboolean. Whether order is ignored when comparing list-like values.
$m.valueboolean. Whether the input matches the pattern.
Common to all components (4)
$m.doenetMLtext. The DoenetML source code that produced this component.
$m.hideboolean. Whether to hide this component from the rendered output.
$m.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$m.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: Default case
The <matchesPattern> component is used to check that the user has supplied an
equation in the requested format. The pattern attribute is required. If used without
additional attributes as shown above, a rather liberal comparison occurs.
- there must be two operands on one side, and none on the other
- one side must contain only (RHS or LHS are acceptable)
- the operands may be
+or-
These requirements may be tightened, if desired, by applying additional
attributes to <matchesPattern>.
Example: Match a specific form of linear equation
In this example, the following conditions must be met:
- a by itself on one side, and an on the other, and no other variables can be present
- the value must have a numerical coefficient, or no coefficient
- switching the order of terms on the right-hand side is acceptable
The attribute requireNumericMatches ensures that the user only enters numerical coefficients
into the ( ) spaces (rather than an x, for example.). Multiple <award> conditions are used to
ensure that the case where does not have a coefficient are allowed.