Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript/Jquery。使用带通配符的正则表达式将纯文本替换为html_Javascript_Regex_Wildcard - Fatal编程技术网

Javascript/Jquery。使用带通配符的正则表达式将纯文本替换为html

Javascript/Jquery。使用带通配符的正则表达式将纯文本替换为html,javascript,regex,wildcard,Javascript,Regex,Wildcard,我想将纯文本(例如)[next 1272]替换为 <a href='page.asp?id=1272'> <img src='next.png' alt='Next Page' title='Next Page' /> </a> 好吧,我想了想,下面的作品,以防对任何人都有帮助。 但不是很优雅 regex = new RegExp(/\[next (.*?)\]/gi); mtch=ThisBody.match(regex) newBody=ThisBody

我想将纯文本(例如)[next 1272]替换为

<a href='page.asp?id=1272'>
<img src='next.png' alt='Next Page' title='Next Page' />
</a>

好吧,我想了想,下面的作品,以防对任何人都有帮助。 但不是很优雅

regex = new RegExp(/\[next (.*?)\]/gi);
mtch=ThisBody.match(regex)
newBody=ThisBody
if (mtch!=null)
  {
  if (mtch.length>0)
    {
    for (var i=0; i<mtch.length; i++)
        {
        tmp=mtch[i]                 // [next 1272]
        tmp=tmp.replace("]","")     // [next 1272
        tmp=tmp.substring(6)        // 1272
        t="<a href='page.asp?id=" + tmp + "'>"
        t+="<img src='Next.png' alt='Next Page' title='Next Page' />"
        t+="</a>"
        newBody=newBody.replace(mtch[i],t) 
        }
    }
  }
ThisBody=newBody
regex=newregexp(/\[next(.*?\]/gi);
mtch=ThisBody.match(正则表达式)
新身体=这个身体
如果(mtch!=null)
{
如果(平均长度>0)
{
对于(var i=0;i
regex = new RegExp(/\[next (.*?)\]/gi);
mtch=ThisBody.match(regex)
newBody=ThisBody
if (mtch!=null)
  {
  if (mtch.length>0)
    {
    for (var i=0; i<mtch.length; i++)
        {
        tmp=mtch[i]                 // [next 1272]
        tmp=tmp.replace("]","")     // [next 1272
        tmp=tmp.substring(6)        // 1272
        t="<a href='page.asp?id=" + tmp + "'>"
        t+="<img src='Next.png' alt='Next Page' title='Next Page' />"
        t+="</a>"
        newBody=newBody.replace(mtch[i],t) 
        }
    }
  }
ThisBody=newBody