Escape Regular Expression Text When Using cy.contains Command @gleb
Escape Regular Expression Text When Using cy.contains Command  @gleb
Uploaded July 2023 | Updated September 2026, 1 week ago
This video shows how to escape special characters like "$", "[]", and "^" when creating regular expressions to use with cy.contains command. You can escape the characters yourself or use the Lodash method Cypress._.escapeRegExp bundled with Cypress to do it for you
const suffix = '$/day'
const regex = new RegExp(Cypress._.escapeRegExp(suffix))
cy.contains(regex).should('have.id', 'rate')
Find the full recipe at glebbahmutov.com/cypress-examples
Escape Regular Expression Text When Using cy.contains CommandShort Demo Of cypress-thinkDisable ServiceWorker In Cypress TestCypress Flaky Test Exercise: Level 1Cypress Flaky Test Exercise: Level 4Validate Email Format Using Built-in Browser Input ElementAdd Cypress AUTWindow PropertiesHandle Telephone And Other Custom Protocol Links In Cypress TestsCheckboxes With ConfirmationCypress Flaky Test Exercise: Level 8Testing Data Preload In TanStack RouterCut Cypress Execution In Half By Running Tests In Parallel Using cypress-split And GitHub Actions
gleb bahmutov |

Escape Regular Expression Text When Using cy.contains Command

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER