Topic: 问一个正则表达式。 |
Print this page |
1.问一个正则表达式。 | Copy to clipboard |
Posted by: uniquejava Posted on: 2007-06-11 18:13 问一个正则表达式。怎么匹配abc后面跟任意个字符? 是不是abc.* 那abc后面跟非abc这个单词的任意字符呢 试了abc[^abc]*不行。因为它的意思是abc后面跟上非a或者非b或者非c |
2.Re:问一个正则表达式。 [Re: uniquejava] | Copy to clipboard |
Posted by: swiftybin Posted on: 2007-06-12 08:06 跟任意个字符是abc.*$ 另一个不知道,,正则不精啊! |
3.Re:问一个正则表达式。 [Re: uniquejava] | Copy to clipboard |
Posted by: JiafanZhou Posted on: 2007-06-12 18:12 uniquejava wrote: abc.*
abc[^abc]*
abc[^abc]* means a followed by b followed by c followed by any character except a, b, or c, zero or more times. So it is right. Regards, Jiafan |
4.Re:问一个正则表达式。 [Re: HenryShanley] | Copy to clipboard |
Posted by: uniquejava Posted on: 2007-06-13 08:28 HenryShanley wrote: thank you, but you mistook my opinion, i mean i need a regular expression means " a followed by b followed by c followed by any character except the whole word 'abc'. that is, given a regular expression, so "abcabd" can match, but "abcabc" can not match help |
5.Re:问一个正则表达式。 [Re: uniquejava] | Copy to clipboard |
Posted by: livahu Posted on: 2007-06-21 09:19 package com.livahu; import java.util.regex.Pattern; public class RegTest { public static void main(String[] args) { boolean flag = Pattern.matches("\\babc(?!abc)(.(?!abc))*\\b", "abcdddadbc"); System.out.println(flag); } } |
6.Re:问一个正则表达式。 [Re: uniquejava] | Copy to clipboard |
Posted by: uniquejava Posted on: 2007-07-31 15:50 一个多月没来了,竟然有人搞出来了!,强!!!感谢! 今天终于明白了,原来用负向前瞻(?!)就可以搞出来! |
7.Re:问一个正则表达式。 [Re: uniquejava] | Copy to clipboard |
Posted by: Cappuccino Posted on: 2007-08-01 01:20 test the following pattern
|
8.Re:问一个正则表达式。 [Re: uniquejava] | Copy to clipboard |
Posted by: uniquejava Posted on: 2007-08-02 11:34 谢谢,又学了一招,用后瞻lookbehind代码确实更简洁。 boolean flag = Pattern.matches("\\babc.*(?<!abc)\\b", "abcdddadbc"); |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |