正则表达式测试斜体和粗体 [英] regexp test for italics and bold

查看:258
本文介绍了正则表达式测试斜体和粗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:


我可以使用一些正则表达式帮助。我正在尝试创建一个

客户端javascript函数,它将测试用户输入以确定已复制到textarea输入字段的文本的标记,

然后会相应地插入html标签。


因此,用户在单词中写入一个包含

斜体实例的文档,粗体和下划线。然后,用户将该

文档的文本复制到我的textarea字段中。我正在尝试创建一个函数,然后

将搜索该标记的所有实例,并将

相应的html标记直接插入textarea字段。


我的问题是我在javascript中找不到regexp或

的方法,否则测试用户输入斜体,粗体或下划线。我在PHP脚本中找到了类似的东西:


//检查斜体文本

$ Text = preg_replace(" ;(\ [i\](。+?)\ [\ / i \])是,< span

class =" italics"> $ 1 < / span>'',$ Text);


但我找不到与此等效的客户端javascript。这个

只需要在最新的IE中工作,因为这是帮助构建HTML电子邮件的内部

工具的一部分。


任何帮助都会非常感激。


谢谢,


Bob

Hello:

I could use some regular expression help. I''m trying to create a
client-side javascript function that will test user input to determine
the markup of text that has been copied into a textarea input field,
then will insert html tags accordingly.

So, the user writes up a document in word that contains instances of
italics, bold, and underline. The user then copies the text of that
document into my textarea field. I am trying to create a function that
will then search through all instances of that markup and insert the
appropriate html tags directly into the textarea field.

My problem is that I cannot find a way in javascript with regexp or
otherwise to test user input for italics, bold, or underline. I found
something similar in a PHP script here:

// Check for Italics text
$Text = preg_replace("(\[i\](.+?)\[\/i\])is",''<span
class="italics">$1</span>'',$Text);

But I cannot find a client-side javascript equivalent to this. This
only needs to work in the latest IE, as this is part of an internal
tool to help build HTML emails.

Any help would be appreciated greatly.

Thanks,

Bob

推荐答案

Text = preg_replace("(\ [i\](。+?)\ [\ / i \]))是,< span

class =" italics">
Text = preg_replace("(\[i\](.+?)\[\/i\])is",''<span
class="italics">


1< / span>'',
1</span>'',


Text);


但我找不到与此相当的客户端javascript。这个

只需要在最新的IE中工作,因为这是帮助构建HTML电子邮件的内部

工具的一部分。


任何帮助都将非常感激。


谢谢,


Bob

Text);

But I cannot find a client-side javascript equivalent to this. This
only needs to work in the latest IE, as this is part of an internal
tool to help build HTML emails.

Any help would be appreciated greatly.

Thanks,

Bob


这篇关于正则表达式测试斜体和粗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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