RegExp拆分为拼写检查 [英] RegExp split for Spell Check

查看:57
本文介绍了RegExp拆分为拼写检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用我的richtext编辑器的拼写检查程序。我不能使用任何开源的

,并且必须自己开发所有东西。我需要一个RegExp

模式来将文本拆分成单词数组。我一直在用

按空格或< ptags分割。我用编辑器的

richtext部分遇到了一个问题。当我更改字体时,它将文本

包装在标签中。标签有类似< font face =" arial>一些单词< /

font这会将文本拆分为font ^ face所以我需要拆分空格

除非它们在HTML标记内。我只是为我的regExp寻找

模式。我知道可能有更好的办法让我这么做,但是现在我只需要帮助解决这个问题。


提前谢谢。


Pete

解决方案

SmokeWilliams于2007年11月23日在comp.lang.javascript中写道


我正在使用我的richtext编辑器的拼写检查器。


我不能使用任何开源,并且必须自己开发所有内容。



为什么?至少看看你能找到的所有代码。从头开始编写复杂的

代码并没有给你带来多年代码的好处

世界程序员集体的实验。


我需要一个RegExp模式将文本拆分成一个单词数组。



为什么?你这样做有关系吗?解析似乎更简单。


我一直在用

按空格或< ptags拆分。我用编辑器的

richtext部分遇到了一个问题。当我更改字体时,它将文本

包装在标签中。


标签的内容类似于< font face =" arial>一些单词< / font>



这是上个世纪的代码。为什么不单独使用< spanand CSS?


这会将文本拆分为font ^ face所以我需要拆分空格

除非他们在HTML标记内。


我只是在寻找我的regExp模式。

我知道我可能有更好的办法

它,但是现在我只需要帮助解决这个问题。



我认为通过规定上述不必要的约束条件,你将会给自己带来很多麻烦。


但是试试这个:


var wordArrray = textString.replace(/(< [^>] *>)/ g,'''')。split (/ \s + /)


-

Evertjan。

荷兰。

(请将我的电子邮件地址中的x'变为点数)


Evertjan。在2007年11月23日下午1:49发表以下内容:


SmokeWilliams于2007年11月23日在comp.lang.javascript 上写道:



< snip>


>标签有东西喜欢< font face =" arial>一些单词< / font>



这是上个世纪的代码。为什么不单独使用< spanand CSS?



因为这是浏览器在contentEditable

元素中放入代码的内容:)


-

兰迪

机会有利于预备心灵

comp.lang.javascript常见问题 - http://jibbering.com/faq/index.html

Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/


Randy Webb于2007年11月23日在comp.lang.javascript中写道


Evertjan。在2007年11月23日下午1:49发表以下内容:


> SmokeWilliams于2007年11月23日在comp.lang.javascript中写道



< snip>


>>标签的内容类似于< font face =" arial>一些单词< / font>


这是上个世纪的代码。为什么不单独使用< spanand CSS?



因为这是浏览器在contentEditable

元素中放入代码的内容。



那么为什么使用contentEditable如果你无法控制呢?


简单的< divwith onkeypress吗?


-

Evertjan。

荷兰。

(请在我的电子邮件地址中将x'变为点数)


Hi,
I am working on a Spell checker for my richtext editor. I cannot use
any open source, and must develop everything myself. I need a RegExp
pattern to split text into a word array. I have been doing it by
splitting by spaces or <ptags. I run into a probelm with the
richtext part of my editor. When I change the font, it wraps the text
in a tag. the tag has something like <font face="arial>some words</
font This splits the text at font^face so I need to split on spaces
unless they are within the HTML tag. I am just looking for the
pattern for my regExp. I know there may be better ways for me to do
it, but right now I just need help with this issue.

Thanks in advance.

Pete

解决方案

SmokeWilliams wrote on 23 nov 2007 in comp.lang.javascript:

I am working on a Spell checker for my richtext editor.

I cannot use any open source, and must develop everything myself.

Why? At least look at all the code you can find. Coming up with complex
code from scratch does not give you the benefit of years of code
experimentation of the collective of world''s programmers.

I need a RegExp pattern to split text into a word array.

Why? Does it matter how you do it? Parsing seems so much simpler.

I have been doing it by
splitting by spaces or <ptags. I run into a probelm with the
richtext part of my editor. When I change the font, it wraps the text
in a tag.

the tag has something like <font face="arial>some words</font>

That is last century''s code. Why not use <spanand CSS exclusively?

This splits the text at font^face so I need to split on spaces
unless they are within the HTML tag.

I am just looking for the pattern for my regExp.
I know there may be better ways for me to do
it, but right now I just need help with this issue.

I think that by stipulating the above unneccessary constraints, you will
get yourself into much trouble.

However try this:

var wordArrray = textString.replace(/(<[^>]*>)/g,'' '').split(/\s+/)

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


Evertjan. said the following on 11/23/2007 1:49 PM:

SmokeWilliams wrote on 23 nov 2007 in comp.lang.javascript:

<snip>

>the tag has something like <font face="arial>some words</font>


That is last century''s code. Why not use <spanand CSS exclusively?

Because that is what the browsers put in the code in a contentEditable
element :)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Randy Webb wrote on 23 nov 2007 in comp.lang.javascript:

Evertjan. said the following on 11/23/2007 1:49 PM:

>SmokeWilliams wrote on 23 nov 2007 in comp.lang.javascript:


<snip>

>>the tag has something like <font face="arial>some words</font>


That is last century''s code. Why not use <spanand CSS exclusively?


Because that is what the browsers put in the code in a contentEditable
element :)

So why use contentEditable if you cannot control it?

Wouldn''t a simple <divwith onkeypress do?

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


这篇关于RegExp拆分为拼写检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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