So I'm working with Cypress and I'm attempting to understand how to verify a URL via regex matching; but I want to use several character sets in the regex, and I want to add a variable as well. Not sure if this is possible but many of the examples I see online aren't offering help.
The main part of the URL to check looks like: /quote/4/8942-4355-p664516?isOptionSelected=false
The block of bolded characters in the middle (8942-4355-p664516) is the changing variable that I need to insert
A normal expression for this would be: /[\S]*\/quote\/\d\/8942-4355-p664516\?isOptionSelected=[\S]*/
As you can see there's a lot of variability, and that changing variable could be taken up with another [/S]* - except that I need to validate that exactly, as part of the URL.
The test errors out if I just create the expression on the fly because it comes out as a string and using something like new RegExp malforms it. Is there a way to generate a regex like this, while inserting that variable into it on the fly?
The main part of the URL to check looks like: /quote/4/8942-4355-p664516?isOptionSelected=false
The block of bolded characters in the middle (8942-4355-p664516) is the changing variable that I need to insert
A normal expression for this would be: /[\S]*\/quote\/\d\/8942-4355-p664516\?isOptionSelected=[\S]*/
As you can see there's a lot of variability, and that changing variable could be taken up with another [/S]* - except that I need to validate that exactly, as part of the URL.
The test errors out if I just create the expression on the fly because it comes out as a string and using something like new RegExp malforms it. Is there a way to generate a regex like this, while inserting that variable into it on the fly?