正则表达式 [英] Regexp

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

问题描述

我在regexp方面很弱,但希望有人在这种情况下知道。

我想尝试这样的网址:


something.lasso?blah = blah& blah2 = blah2& sort = hello& b lah3 = blah3


并删除& sort = XXX而不会伤害其余网址。要替换的参数

将是传递给函数的参数。这是我到目前为止所获得的



函数刷新(项目){

current = document.location.href;

if(current.match(item.name +''=''))

//伪代码在这里

//current.replace (item.name regexp,'''');


return(当前+"&" + item.name +" =" + item.value);


这个函数将被解雇:


All< input type =" radio"名称= QUOT;显示" value =" all"

onclick =" document.location = refresh(this);">

Mine< input type =" radio"名称= QUOT;显示" value =" mine"

onclick =" document.location = refresh(this);">

如有任何建议,敬请谅解!


-S

I am weak when it comes to regexp but hoped someone might know in this case.
I am trying to take a url like this :

something.lasso?blah=blah&blah2=blah2&sort=hello&b lah3=blah3

And remove the &sort=XXX without hurting the rest of the url. The parameter
to be replaced would be a parameter passed to a function. Here is what I
have so far:

function refresh(item) {
current = document.location.href;
if(current.match(item.name+''=''))
//pseudo code here
//current.replace(item.name regexp , '''');

return (current + "&" + item.name + "=" + item.value);

This function would be fired like this :

All <input type="radio" name="show" value="all"
onclick="document.location=refresh(this);">
Mine <input type="radio" name="show" value="mine"
onclick="document.location=refresh(this);">
Any suggestions are appreciated!

-S

推荐答案

Phat G5(G3)于2005年12月26日在comp.lang.javascript中写道< b> :
Phat G5 (G3) wrote on 26 dec 2005 in comp.lang.javascript:
关于regexp,我很弱,但希望有人可能知道这个案例。我想尝试这样的网址:

something.lasso?blah = blah& blah2 = blah2& sort = hello& b lah3 = blah3

并删除& ; sort = XXX而不会伤害其余网址。要替换的
参数将是传递给函数的参数。
I am weak when it comes to regexp but hoped someone might know in this
case. I am trying to take a url like this :

something.lasso?blah=blah&blah2=blah2&sort=hello&b lah3=blah3

And remove the &sort=XXX without hurting the rest of the url. The
parameter to be replaced would be a parameter passed to a function.




str =''something.lasso?blah = blah& blah2 = blah2&排序=你好&安培; blah3 = blah3''


alert(str)


str = str.replace(/ sort = [^&] *& ?/,'''')


alert(str)

-

Evertjan。

荷兰。

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



str = ''something.lasso?blah=blah&blah2=blah2&sort=hello& blah3=blah3''

alert(str)

str = str.replace(/sort=[^&]*&?/,'''')

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


Evertjan。 2005年12月26日在comp.lang.javascript中写道
Evertjan. wrote on 26 dec 2005 in comp.lang.javascript:
Phat G5(G3)于2005年12月26日在comp.lang.javascript中写道
Phat G5 (G3) wrote on 26 dec 2005 in comp.lang.javascript:
我对regexp很弱,但希望有人可能知道这个案例。我想尝试这样的网址:

something.lasso?blah = blah& blah2 = blah2& sort = hello& b lah3 = blah3

并删除& ; sort = XXX而不会伤害其余网址。要替换的
参数是传递给函数的参数。
I am weak when it comes to regexp but hoped someone might know in this
case. I am trying to take a url like this :

something.lasso?blah=blah&blah2=blah2&sort=hello&b lah3=blah3

And remove the &sort=XXX without hurting the rest of the url. The
parameter to be replaced would be a parameter passed to a function.



str =''something.lasso?blah = blah& blah2 = blah2& sort = hello& blah3 = blah3''

警报(str)

str = str.replace(/ sort = [^&] *&?/,'''')

alert(str)



str = ''something.lasso?blah=blah&blah2=blah2&sort=hello& blah3=blah3''

alert(str)

str = str.replace(/sort=[^&]*&?/,'''')

alert(str)




对不起,不对,发送按钮太快按下了,试试这个:

str =''something.lasso?blah = blah& blah2 = blah2& sort = hello& blah3 = blah3''


str = str.replace(/&?sort = [^&] * /,'''')


alert(str)


str =''something.lasso?blah = blah& blah2 = blah2& sort = hello''


str = str.replace(/&?sort = [^&] * /,'''')


alert(str)


-

Evertjan。

荷兰。

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



Sorry, incorrect, the send button was pressed too soon, try this:

str = ''something.lasso?blah=blah&blah2=blah2&sort=hello& blah3=blah3''

str = str.replace(/&?sort=[^&]*/,'''')

alert(str)

str = ''something.lasso?blah=blah&blah2=blah2&sort=hello''

str = str.replace(/&?sort=[^&]*/,'''')

alert(str)

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


,文章Xn********************@194.109.133.242,Evertjan。在
ex ************** @ interxnl .net 于12/26/05 8:19 AM写道:
in article Xn********************@194.109.133.242, Evertjan. at
ex**************@interxnl.net wrote on 12/26/05 8:19 AM:
Evertjan。 2005年12月26日在comp.lang.javascript中写道
Evertjan. wrote on 26 dec 2005 in comp.lang.javascript:
Phat G5(G3)于2005年12月26日在comp.lang.javascript中写道
Phat G5 (G3) wrote on 26 dec 2005 in comp.lang.javascript:
我对regexp很弱,但希望有人可能知道这个案例。我想尝试这样的网址:

something.lasso?blah = blah& blah2 = blah2& sort = hello& b lah3 = blah3

并删除& ; sort = XXX而不会伤害其余网址。要替换的
参数是传递给函数的参数。
I am weak when it comes to regexp but hoped someone might know in this
case. I am trying to take a url like this :

something.lasso?blah=blah&blah2=blah2&sort=hello&b lah3=blah3

And remove the &sort=XXX without hurting the rest of the url. The
parameter to be replaced would be a parameter passed to a function.



str =''something.lasso?blah = blah& blah2 = blah2& sort = hello& blah3 = blah3''

警报(str)

str = str.replace(/ sort = [^&] *&?/,'''')

alert(str)



str = ''something.lasso?blah=blah&blah2=blah2&sort=hello& blah3=blah3''

alert(str)

str = str.replace(/sort=[^&]*&?/,'''')

alert(str)



抱歉,不正确,发送按钮过早按下,试试这个:

str =' something.lasso等等=等等&安培; blah2 = blah2&安培;排序=你好&安培; blah3 = blah3''

str = str.replace(/&?sort = [^&] * /,'''')

alert(str)

str =''something.lasso?blah = blah& blah2 = blah2& sort = hello''

str = str.replace(/&?sort = [ ^&] * /,'''')

alert(str)



Sorry, incorrect, the send button was pressed too soon, try this:

str = ''something.lasso?blah=blah&blah2=blah2&sort=hello& blah3=blah3''

str = str.replace(/&?sort=[^&]*/,'''')

alert(str)

str = ''something.lasso?blah=blah&blah2=blah2&sort=hello''

str = str.replace(/&?sort=[^&]*/,'''')

alert(str)



我很欣赏这一点。它几乎完美。我的ISP显然发送速度很快但是b $ b收到了SLOW。我在30分钟前看到谷歌的反应。无论如何,我已经玩过它并发现了一个很小的难度。我试图将
变量放入reg exp中,就像我在公式中看到的那样。我试过各种各样的差异,比如


str =''something.lasso?blah = blah& blah2 = blah2& sort = hello''

item =" sort";


// str = str.replace(/&?sort = [^&] * /,'''' ')

// str2 = eval(" /&?" + item +" = [^&] * /");

str3 = /&?(item)= [^&] * /;

alert(str3);

// str2 = new RegExp(str3," gi" ;);


str = str.replace(str3,'''')


alert(str)

如何将评估变量放入正则表达式?


-S


I appreciate this. It almost perfect. My ISP apparently sends fast but
receives SLOW. I saw the response on google over 30 minutes ago. Anyhow, I
have been playing with it and have found a small difficulty. I am trying to
place a variable into the reg exp as you may have seen in my formula. I
tried all sorts of variances like

str = ''something.lasso?blah=blah&blah2=blah2&sort=hello''
item="sort";

//str = str.replace(/&?sort=[^&]*/,'''')
//str2 = eval("/&?" + item + "=[^&]*/");
str3 = /&?(item)=[^&]*/;
alert(str3);
//str2 = new RegExp(str3, "gi");

str = str.replace(str3,'''')

alert(str)
How do I get the evaluated variable into the regexp?

-S


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

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