简体   繁体   English

用于 PHP 的 JavaScript 等效 RegExp

[英]JavaScript equivalent RegExp for PHP

Im looking for JavaScript equivalent RegExp for PHP.我正在寻找用于 PHP 的 JavaScript 等效 RegExp。

This PHP RegExp class must have same methods with same returns as JavaScript version.这个 PHP RegExp 类必须具有与 JavaScript 版本相同的方法和相同的返回值。

I can not find anything.我找不到任何东西。

Thanks谢谢

[EDIT] [编辑]

I need same class in PHP as is in JavaScript.我需要在 PHP 中使用与 JavaScript 中相同的类。 preg_match methods in php has different results as RegExp.exec in JavaScript. php 中的 preg_match 方法与 JavaScript 中的 RegExp.exec 有不同的结果。 And also has different flags也有不同的标志

You can use Javascript RegExp object in order to accomplish what you want.您可以使用 Javascript RegExp对象来完成您想要的。

Here's an example taken from MDN:这是从 MDN 中获取的示例:

var re = /(\w+)\s(\w+)/;
var str = 'John Smith';
var newstr = str.replace(re, '$2, $1');
console.log(newstr);

You can check more of them here .你可以在这里查看更多。

I really don't believe you searched all that hard.我真的不相信你会那么努力地寻找。 Top google result for "PHP RegEx": http://php.net/manual/en/function.preg-match.php “PHP RegEx”的顶级谷歌结果: http : //php.net/manual/en/function.preg-match.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM