In literal mode, all the contents wrapped between // are metacharacters, some have special meanings, and most of them are ordinary metacharacters that represent their own meaning
varname ='wo';
varreg = /^\d " name "\d $/
In order to solve the above-mentioned need to add a variable to the regular expression, we can only use the instance creation method
varreg =newRegExp("^\\d " name "\\d $","g")
What is the difference between literal method and instance creation method in regular expressions?
1. Everything that appears in the literal method is metacharacters, so variable values cannot be spliced, but the instance creation method is possible.
2. Just write \d directly in the literal, but in the example it needs to be translated as \\d
All resources on this website are contributed and published by netizens, or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this website are for learning and reference only. Please do not use them for commercial purposes, otherwise you will be responsible for all consequences incurred! If there is any infringement, please contact us to delete and remove it. Contact information: admin@php.cn