url匹配的正则表达式

时间:2010-10-07 09:17:50

标签: javascript jquery regex javascript-events

我的文字字段的值为http://localhost/Send/test.php?s/?a=1&o=2。另外三个文本框。如果我们输入三个值,则上述网址将更改为http://localhost/Send/test.php?s/?a=1&o=2&s1=a&s2=b&s3=cs1,s2s3的值不会保存在任何地方。我的问题是我们如何检查已设置s1的值?如果我更改s1 alt text

的文本框值,如何更新s1的值

3 个答案:

答案 0 :(得分:0)

您可以使用此正则表达式替换

url.replace(/&s1=([^$]+|[^&]+)/i, "&s1=newvalue");

答案 1 :(得分:0)

我邀请你在PHP中使用PCRE:

(?=(?P<ES1>.*&s1=)?)(?(ES1)RegexToMatchIfS1AlreadyExist|RegexToMatchIfS1NotExist)

所以

$result = preg_replace('/^(?=(?P<ES1>.*&s1=)?)(?(ES1)(?P<Left>.*&s1=)(?P<Right>.*+)$|RegexToMatchIfS1NotExist)/', '${1}newvalue${2}', ...);

答案 2 :(得分:0)

为每种语言使用此安全正则表达式...

^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$
相关问题