如何将此 PHP 正则表达式转换为 Javascript 正则表达式? [英] How to convert this PHP Regex to Javascript Regex?

查看:72
本文介绍了如何将此 PHP 正则表达式转换为 Javascript 正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

老实说,我对正则表达式很讨厌,我需要大量的帮助来制作这个 PHP 正则表达式.尽管如此,我已经决定需要将大量代码转换为 Javascript.

Honestly, I am horrible with regular expressions and I needed a ton of help making this PHP regex. Although, I have decided that I need to convert a ton of my code to Javascript.

这是我的 PHP 正则表达式:

Here is my PHP regex:

if(preg_match('/^(([^,]+,){4}[^,]+\n){3}$/', $all_questions))

有人可以帮我将它转换为 Javascript 正则表达式吗?

Could someone give me a hand on converting it to a Javascript regex?

非常感谢,谢谢!

推荐答案

在 JS 中,你可以做一个简单的 .test() 与正则表达式(无需更改表达式).

In JS, you can do it simple do a .test() with Regex(no need to change the expression).

var yourRegEx=/^(([^,]+,){4}[^,]+\n){3}$/;
if(yourRegEx.test($all_questions) {  // replace $all_questions with your
                                     // js variable
}

这篇关于如何将此 PHP 正则表达式转换为 Javascript 正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆