正则表达式 - 如何把一个PHP中递归正则的语句替换为JavaScript非递归的语句?

WBOY
Libérer: 2016-06-06 20:42:59
original
1060 Les gens l'ont consulté

最近正在做一个js版本的markdown解析库,打算将网上比较流行的一个名为Parsedown的库完整的迁移到js上,这样前后端就有相同的展现效果了,但是我发现它的原作者在使用正则时用到了递归,但js正则又是不支持递归的,所以寻求一个解决方法能完美迁移,下面是PHP代码,注意preg_match部分

<code class="lang-php">    protected function identifyLink($Excerpt)
    {
        $extent = $Excerpt['text'][0] === '!' ? 1 : 0;

        if (strpos($Excerpt['text'], ']') and preg_match('/\[((?:[^][]|(?R))*)\]/', $Excerpt['text'], $matches))
        {
</code>
Copier après la connexion
Copier après la connexion

回复内容:

最近正在做一个js版本的markdown解析库,打算将网上比较流行的一个名为Parsedown的库完整的迁移到js上,这样前后端就有相同的展现效果了,但是我发现它的原作者在使用正则时用到了递归,但js正则又是不支持递归的,所以寻求一个解决方法能完美迁移,下面是PHP代码,注意preg_match部分

<code class="lang-php">    protected function identifyLink($Excerpt)
    {
        $extent = $Excerpt['text'][0] === '!' ? 1 : 0;

        if (strpos($Excerpt['text'], ']') and preg_match('/\[((?:[^][]|(?R))*)\]/', $Excerpt['text'], $matches))
        {
</code>
Copier après la connexion
Copier après la connexion

Github 官方出了个解析脚本,何必还自己去写

https://github.com/jgm/stmd

下载 js 下面那个 stmd.js 就是

看看这个,php-to-js https://github.com/Danack/PHP-to-Javascript

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!