str.replace [英] str.replace

查看:99
本文介绍了str.replace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用regxp来检查表单输入是否包含至少1个

非空格字符。如果浏览器支持

,我只想运行它。对于DOM的东西,我会使用


if(documentGetElementById){}


是否有对象/特征检测我可以使用检查regxp字符串

操作支持?


-

Brian(删除.invalid给我发电子邮件)
http://www.tsmchughs.com/

I want to use regxp to check that a form input contains at least 1
non-space charcter. I''d like to only run this if the browser supports
it. For DOM stuff, I''d use

if (documentGetElementById) {}

Is there an object/feature detection I can use to check for regxp string
manipulation support?

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/

推荐答案

On Sun,2004年8月15日11:40:30 -0400,Brian

< us ***** @ julietremblay.com 。无效>写道:
On Sun, 15 Aug 2004 11:40:30 -0400, Brian
<us*****@julietremblay.com.invalid> wrote:
我想使用regxp检查表单输入是否包含至少1个非空格字符。如果浏览器支持它,我想只运行它。
对于DOM的东西,我会使用

if(documentGetElementById){}


你的意思是


if(document.getElementById)...

是否有对象/特征检测我可以用来检查regxpstring
I want to use regxp to check that a form input contains at least 1
non-space charcter. I''d like to only run this if the browsersupports it.
For DOM stuff, I''d use

if (documentGetElementById) {}
You mean

if(document.getElementById) ...
Is there an object/feature detection I can use to check for regxpstring
manipulation support?




没有必要。自v1.2起,JavaScript中存在正则表达式

(NN4)。你需要测试的唯一一件事就是支持更新的

可用的构造(前瞻性匹配等)。


希望有帮助,

迈克


-

Michael Winter

替换.invalid与.uk通过电子邮件回复



There''s no need. Regular expressions have existed in JavaScript since v1.2
(NN4). The only thing you do need to test is that more recent additions to
the available constructs (lookahead matches and the like) are supported.

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail


Brian写道:
我想使用regxp检查表单输入是否包含至少1个非空间特征。如果浏览器支持它,我想只运行它。对于DOM的东西,我会使用

if(documentGetElementById){}


假设你的意思是: -


if(document.getElementById){}

- 推断任何级别的DOM支持(特别是

动态DOM支持)形式是不顾后果的测试。唯一有效的演绎可用

表格,该测试是浏览器支持的 - document.getElementById -

(知道你是否打算使用它而非整个画面很有用)。


是否有对象/特征检测我可以用来检查
regxp字符串操作支持?
I want to use regxp to check that a form input contains at least 1
non-space charcter. I''d like to only run this if the browser supports
it. For DOM stuff, I''d use

if (documentGetElementById) {}
Assuming you mean:-

if (document.getElementById) {}

- it would be reckless to infer any level of DOM support (especially
dynamic DOM support) form that test. The only valid deduction available
form that test is that the browser supports - document.getElementById -
(useful to know if you intend using it but not the whole picture).

Is there an object/feature detection I can use to check for
regxp string manipulation support?




因为你的subjuect意味着对字符串的兴趣 - 替换 - 方法: -


if(

(typeof String ==''function'')& &

(String.prototype)&&

(String.prototype.replace)

){

... // String.prototype.replace可用。

}


虽然实际上你可以期待有一个 - 替换 - 方法

可用于当前正在使用的所有浏览器javascript实现

(仍然,确保无害)。


String的功能。 prototype.replace可能还需要测试: -


< URL:
http://jibbering.com/ faq / faq_notes / n ... html #bdReplace >


不幸的是,jibbering.com目前似乎无法使用,所以这个

是该页面中使用的代码: -


/ *原始字符串是单字母字符串文字a。

正则表达式/ a /标识整个字符串,因此它将被替换为

整个原始字符串。第二个参数是

函数表达式 - function(){return'''''';} - 所以整个

原始字符串将被替换为空字符串如果执行

函数表达式。如果它被类型转换为
到一个字符串,该字符串将不是一个空字符串。 NOT(!)

操作类型 - 将其操作数转换为布尔值然后将其反转

因此如果函数引用,则测试结果为布尔值true
$ - replace - 方法的第二个参数支持b $ b,不支持时支持
false:

* /

if( !(''a''。replace(/ a /,(function(){return'''';})))){

... //函数引用OK。

} else {

... //没有带替换的函数引用。

}


如果你想要不同的,或更具体的正则表达式测试然后

真正问题的本质定义了适当的测试,你还没有阐明真实的情况/问题。


Richard。



As your subjuect implies an interest in the string - replace - method:-

if(
(typeof String == ''function'') &&
(String.prototype) &&
(String.prototype.replace)
){
... // String.prototype.replace is available.
}

Though realistically you can expect to have a - replace - method
available on all browser javascript implementations currently in use
(still, no harm in making sure).

The capabilities of String.prototype.replace might be additionally
tested with:-

<URL:
http://jibbering.com/faq/faq_notes/n...html#bdReplace >

Unfortunately jibbering.com appears to be unavailable at present so this
is the code used in that page:-

/* The original string is the one letter string literal "a". The
Regular Expression /a/ identifies that entire string, so it is the
entire original string that will be replaced. The second argument is
the function expression - function(){return '''''';} -, so the entire
original string will be replaced with an empty string if the
function expression is executed. If it is instead type-converted
into a string that string will not be an empty string. The NOT (!)
operation type-converts its operand to boolean and then inverts it
so the results of the test is boolean true if function references
are supported in the second argument for the - replace - method, and
false when not supported:
*/
if(!(''a''.replace(/a/, (function(){return '''';})))){
... //function references OK.
}else{
... //no function references with replace.
}

If you want different, or more specific, regular expression testing then
the nature of the real problem defines the appropriate test and you have
not yet elucidated the real circumstances/problem.

Richard.


On Sun,2004年8月15日17:30:02 +0100,Richard Cornford

< Ri ***** @ litotes.demon.co.uk>写道:
On Sun, 15 Aug 2004 17:30:02 +0100, "Richard Cornford"
<Ri*****@litotes.demon.co.uk> wrote:
Brian写道:
< URL:
http://jibbering.com/faq/faq_notes/n...html#bdReplace >

不幸的是jibbering.com目前似乎不可用,所以这个
是该页面中使用的代码: -
Brian wrote:
<URL:
http://jibbering.com/faq/faq_notes/n...html#bdReplace >

Unfortunately jibbering.com appears to be unavailable at present so this
is the code used in that page:-




我不会详细说明为什么它''聋子,但是我不高兴。

兔子...希望在英国时间星期一下午的某个时候回来。


向大家道歉! br />

吉姆。



I won''t go into the details why it''s deaf, but I''m not happy a
bunny... hopefully back sometime in the afternoon of monday UK time.

Apologies everyone!

Jim.


这篇关于str.replace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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