Neighborhoods regular expression handling strings.

Category: Web Develop
 
ZY_Lee
2011-02-12 05:58:25

Sponsored Links
The test.htm? Method = gettest & id = 123 index.htm? Method = test & id = abc
into test_gettest_123.html index_test_abc.html
as long as these string handling, interception try to use regular expressions to match.

Sponsored Links

lfz3210
2011-02-12 06:18:21
str = str.replaceAll("(\\w+)\\.htm\\?method=(\\w+)&id=(\\w+)", "$1_$2_$3.html");
asp_plus
2011-02-12 06:21:14


var url = "test.htm?method=gettest&id=123  index.htm?method=test&id=abc ";
var pattern = /([^\.]+)\.([^\?]+)\?method=([^\&]+)\&id=(\S+)/g;
var rep = url.replace(pattern,"$1_$3_$4\.$2");
document.write(rep);

Jacky0056
2011-02-12 06:40:39

The above is not written yet, use \ \?
where \ \ is the java escape \, and \? is regular escape?
tlzmq
2011-02-12 06:45:09
l javascript regular floor, 2 House java regular.
CAlfred
2011-02-12 06:49:56
1,2 F wrote are good
Lwmjm
2011-02-12 07:00:20
? with \? lieu

right
but you should use the time
specific string is replaced directly into the bar
this time is the need to deal with the
w563412w
2011-02-12 07:14:38
Thank you, with a small problem
"/ main.jsppid = 1". replaceAll ("/ main.jsppid = ([a-zA-Z0-9] +)", "/ $ 1.html" ;) can,
but with? No. "/ main.jsp? pid = 1". replaceAll ("/ main.jsp? pid = ([a-zA-Z0-9] +) "," / $ 1.html ") can not,
hello escape is \ \ u003F but specifically how to use? To make / main.jsp? Pid = 1 becomes 1.html
zym9527
2011-02-12 07:19:09
do not write their own regular, every time you use must be checked. . . Lazy, did not learn in depth frequently used ~ trouble you.
tai_duo_le
2011-02-12 07:27:02

I use \? lieu tried, useless. . .
lena3140
2011-02-12 07:43:18

String str = "http://localhost:8080/main.jsp?pid=2".replaceAll("/main.jsp?pid=([a-zA-Z0-9]+)", "/$1.html");
System.out.println(str);
no reaction, does not automatically replace the

String str = "http://localhost:8080/main.jsppid=2".replaceAll("/main.jsppid=([a-zA-Z0-9]+)", "/$1.html");
System.out.println(str);
will be replaced So am at a loss to know about? reserved characters but did not solve the problem of method. . .
zhangaquan
2011-02-12 07:58:50

String str = "http://localhost:8080/main.jsp?pid=2".replaceAll("/main.jsp\\?pid=([a-zA-Z0-9]+)", "/$1.html");
System.out.println(str);
ghostDarkCrystal
2011-02-12 08:03:13
Thank you, doing urlrewrite reverse resolution.
<rule>
<from> / main.jsp \ \? pid = ([a-zA-Z0-9] +) </from>
<to type = "forward"> / $ 1.html </to>
</rule>
urlrewrite in or not, but the regular expression is correct, can be used. Results posted a ~
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.