# Match assertion

If the current subject is a jQuery element, the match assertion uses jQuery .is (opens new window) method to check if the element matches the selector. If the current subject is text, the match assertion checks it against the given regular expression.

Watch the video Using Should Match Assertion Against Elements Or Text (opens new window) or continue reading.

# Match jQuery element selector

<div id="one" class="btn btn-large">First</div>
cy.contains('div', 'First')
  // the current subject should match the selector
  // "#one.btn-large"
  .should('match', '#one.btn-large')
  // we can use other jQuery selectors like
  // :contains to confirm the text
  .and('match', 'div:contains("First")')

# Match the text using regular expression

<div id="fruit">Orange</div>
// using https://on.cypress.io/contains
cy.contains('#fruit', /(orange|apple|grape)/i)
// using the "match" assertion
  .should('match', /orange/i)