I have this line of code in javascript
var re = (http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?
Usually I encapsulate the regex syntax with the /
characters but since they are found within the regex it screws up the encapsulation. Is there another way how I can store it inside the variable?
The current slashes that seem like escape characters are part of the regex, since I am using this in c# aswell and works perfectly
var re = new RegExp("^your regexp.*$", "gi");
One way is to escape all occurances of /
in your regex as \/
, like you're already partially doing:
var re = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With