如何在正则表达式中使用斜杠和双引号?

时间:2022-09-15 15:35:36

I'm using a validation script called VDAEMON and in applying it to an element we have to set the type of characters we want allowed in a field with a regular expression. Due to the fact that the purpose my element serves is for people to explain things I want them to be able to pretty much have full keyboard usage to express their ideas.

我正在使用名为VDAEMON的验证脚本,并将其应用于元素时,我们必须在具有正则表达式的字段中设置我们想要的字符类型。由于我的元素所服务的目的是让人们解释我希望他们能够完全使用键盘来表达他们的想法。

So far I came up with this to allow all the characters

到目前为止,我想出了这个允许所有角色

regexp="/^[0-9a-z!@#$%^&*():;<>,.?\/\s]*$/i"

The only ones I can't get to work is the /\ and ". Of course the " changes the html structure and the / and \ are used in the syntax, which I'm not too sure on which language that is I just kinda winged it with the other characters and tested it and it happened to work.

我唯一无法工作的是/ \和“。当然”改变了html结构和/和\在语法中使用,我不太确定哪种语言就是我只是有点用其他角色飞过它并测试它,它碰巧工作了。

It did say it needed to be any perl compatible expression. Does anybody know how to achieve this?

它确实说它需要是任何perl兼容的表达式。有谁知道如何实现这个目标?

///////////////////////UPDATE///////////////////////////////

/////////////////////// UPDATE ////////////////////////// /////

Here's a sample of the HTML I'm trying to call it in

这是我试图称之为HTML的HTML示例

<textarea id="my_comp" name="How_did_you_hear_about_my_Company" class="tex_inp01" style="width:88%; height:100px; font-size:14pt;"></textarea>
<vlvalidator name="My_Company" type="regexp" control="How_did_you_hear_about_my_Company" errmsg="Invalid Type Format" regexp="/^[0-9a-z!@#$%^&*():;<>\\,.?\/\s]*$/i">

1 个解决方案

#1


1  

Try single quotes.

试试单引号。

preg_match('~^[0-9a-z!@#$%^&*():;<>,.?/\s"]*$~i', $str);

#1


1  

Try single quotes.

试试单引号。

preg_match('~^[0-9a-z!@#$%^&*():;<>,.?/\s"]*$~i', $str);