ReferencematchesPattern

<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>
AttributeTypeValues
allowedErrorInNumbers = "…"number
allowedErrorIsAbsolute = "…"boolean"true" "false"
allowImplicitIdentities = "…"boolean"true" "false"
allowPermutations = "…"boolean"true" "false"
caseInsensitiveMatch = "…"boolean"true" "false"
excludeMatches = "…"mathList
expandOnCompare = "…"boolean"true" "false"
includeErrorInNumberExponents = "…"boolean"true" "false"
matchBlanks = "…"boolean"true" "false"
matchByExactPositions = "…"boolean"true" "false"
matchExpressionWithBlanks = "…"boolean"true" "false"
numPeriodicSetMatchesRequired = "…"integer
numSignErrorsMatched = "…"number
pattern = "…"
requireNumericMatches = "…"boolean"true" "false"
requireVariableMatches = "…"boolean"true" "false"
simplifyOnCompare = "…"text"none" "full" "numbers" "numberspreserveorder"
symbolicEquality = "…"boolean"true" "false"
unorderedCompare = "…"boolean"true" "false"
Props for <matchesPattern name="m">
PropertyType
$m.allowedErrorInNumbersnumber
$m.allowedErrorIsAbsoluteboolean
$m.allowImplicitIdentitiesboolean
$m.allowPermutationsboolean
$m.caseInsensitiveMatchboolean
$m.disabledboolean
$m.excludeMatchesmathList
$m.expandOnCompareboolean
$m.fixedboolean
$m.fixLocationboolean
$m.hiddenboolean
$m.includeErrorInNumberExponentsboolean
$m.matchBlanksboolean
$m.matchByExactPositionsboolean
$m.matchExpressionWithBlanksboolean
$m.numMatchesnumber
$m.numPeriodicSetMatchesRequiredinteger
$m.numSignErrorsMatchednumber
$m.patternMatches[ math ]
$m.requireNumericMatchesboolean
$m.requireVariableMatchesboolean
$m.simplifyOnComparetext
$m.symbolicEqualityboolean
$m.texttext
$m.unorderedCompareboolean
$m.valueboolean

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 yy (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 yy by itself on one side, and an xx on the other, and no other variables can be present
  • the xx 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 xx does not have a coefficient are allowed.