Enter your regex: a?
Enter input string to search: ababaaaab
I found the text "a" starting at index 0 and ending at index 1.
I found the text "" starting at index 1 and ending at index 1.
I found the text "a" starting at index 2 and ending at index 3.
I found the text "" starting at index 3 and ending at index 3.
I found the text "a" starting at index 4 and ending at index 5.
I found the text "a" starting at index 5 and ending at index 6.
I found the text "a" starting at index 6 and ending at index 7.
I found the text "a" starting at index 7 and ending at index 8.
I found the text "" starting at index 8 and ending at index 8.
I found the text "" starting at index 9 and ending at index 9.nothing不明白在 b 的位置上,为什么匹配到了 "" ?????
或者说这个 "" 根本就不是在 b 的位置上匹配到的????
匹配到的空串是哪里来的呢????*****************************************************然后在问一个有点相关的问题
Enter your regex: a?
Enter input string to search: a
I found the text "a" starting at index 0 and ending at index 1.
I found the text "" starting at index 1 and ending at index 1.
里面还有这么一句话
Remember, the matcher sees the character "a" as sitting in the cell between index 0 and index 1, and our test harness loops until it can no longer find a match.
上面的这段话的意思好像是说 “匹配器matcher 认为 "a" 就坐落在 index 0 和 index 1 之间”
不过我觉得:"a" 就是在index 0上啊(我认为字符是在index上面坐着,而不是坐在index之间去),怎么会跑到索引之间去呢???就想我们在处理String时,index 0 上面就放着一个字符,index 2 上发着另外一个字符。。字符怎么会“坐落到索引之间去呢”??????

解决方案 »

  1.   

    又是我来啦~~~
    正则表达式的索引和数组的是不一样的,例如字符串abc对应的索引是
    [0]a[1]b[1]c[2]  (因为这里画不了图,所以只能用[]表示索引了)
    所以a在索引0和1之间,其他类推这是java tutorial 上的例子,上面说得很详细啦,你是不是跳过前面的几节没看?看一下String literals这一节
      

  2.   

    C_program_Baby() ( ) 信誉:100    Blog  2006-12-2 21:10:28  得分: 0  
        
    ?是指0个或1个吧 那后面的空格也应该包括里面============
    应该是这样吧另外不太清楚LZ想要匹配什么
      
     
      

  3.   

    a?
    它是跟任何字符都匹配的:是'a',它匹配到了'a';不是,它拿空白匹配上了.
    字符串都是有个结束标志'\0'的:正则表达式可以匹配到边界的,所以会多出一个
      

  4.   

    XXKKFF(讠古 钅)
    大哥,缘分呢,你又来了 谢谢谢谢
    我还真的没有看前面的,直接就看的 数量表示符,重点是看英文的头疼啊,不大想看!!!谢谢谢谢,十分感谢!!!