简介 目录 评价 推荐
  • 荼灬 2020-11-24
    为什么下面这句代码匹配为空呢? 正则表达式不是去匹配"123abc"中的子串吗?"abc"是符合表达式要求的啊

    我查到的资料说是re.match是从头开始匹配,如果开头没有,就匹配不上

    1回答·590浏览
  • 两年内要成大神 2020-02-02
    为什么 我的 \w 匹配不到呢? 还有

    \Aimooc表示以imooc开头的字符串,你后面匹配的是Aimooc开头的,所以匹配不到。这里\A表示的是以指定字符串开头,老师讲义里有讲

    1回答·873浏览
  • 大龙猫_ 2019-12-22
    这点不太懂,有大神解释吗?

    小括号代表使用了分组,正则语法就是这样,不必纠结.就像python遇到xxx()就知道是调用函数一样.

    \1 等于 前面括号里的匹配规则,就相当于  ([\w]+>)\1  =  ([\w]+>)[\w]+>两次这个匹配规则.你可以理解成\1是个变量,保存了前面括号里的匹配语法并使用  即 \1 = (匹配语法),   使用\1 就是使用括号里语法    有帮助的话请给个最佳回答


    1回答·878浏览
  • 钓鱼的优卡斯 2018-12-19
    版本的问题?

    问题都描述不清楚? 什么问题?

    1回答·1159浏览
  • 守夜人_96 2018-10-23
    关于python问题

    我试了下可以啊(python3)

    import urllib3
    http = urllib3.PoolManager()
    html = http.request('get', 'https://www.imooc.com').data.decode()
    print(html)


    1回答·1198浏览
  • 慕瓜9435863 2018-07-15
    在python正则表达式中\1是什么意思???
    已采纳 redrose2100 的回答

    \1表示使用编号为1的分组,在前面有个括号([\w]+>) 这个括号内的就表示是编号为1的分组,如果这个正则表达式中有多个括号,就是说有多个分组,然后想复用第n个分组,就加一个\n,就OK了,不知道有没有说清楚


    3回答·10138浏览
  • 慕粉1637381988 2018-06-11
    关于“.”

    问得好?

    2回答·1193浏览
  • 慕粉2244113937 2018-04-05
    ^ 和 \A 啥区bie?

    比如匹配ioo,^ioo匹配的必须是以i开头的,用\A必须是匹配以ioo开头的

    1回答·1339浏览
  • python_不屈菜鸟 2018-03-09
    分组匹配的问题

    因为后边的字符串'<book>'不满足前面的前面的正则要求,重点是弄明白\1是什么意思。可以做两个测试:

    测试1:pa = re.match(r'<([\w]+>)\1', '<book>book>')
    pa.groups()

    测试2:pa = re.match(r'<([\w]+>)', '<book>')
    pa.groups()

    3回答·974浏览
  • 谦曰盛 2018-03-01
    关于 match 匹配和 $ 的问题
    [\w]{4,10}@163.com$

    我想是先匹配后边‘@163.com’,然后找前边的字符4到10位

    1回答·1161浏览
  • 希希同学 2017-12-25
    re.match(r'<([\w]+>)[\w]+</\1','<book>python</book>')问题
    已采纳 qq_爱吃羊的鲸鱼_0 的回答

    \1就是代表了前面“([\w]+>)”这些内容,你将\1替换掉就成了ma=re.match(r'<([\w]+>)[\w]+</([\w]+>)','<book>python</book>')  其中括号已经没有意义,去掉后就变成ma=re.match(r'<[\w]+>[\w]+</[\w]+>','<book>python</book>')  这样看就应该没问题了吧。

    后面加1匹配不出来的原因也是应为</book>这个字符串匹配不到的缘故。

    1回答·2567浏览
  • weibo_海山征_0 2017-10-15
    第二个>怎么匹配出来的

    你仔细看清楚他第一个分组是(book>)已经包含了>

    1回答·1364浏览
  • qq_LWQ_1 2017-09-17
    [1-9]?\d$ 匹配09时应该能匹配到9吧??

    大爷的,没仔细看。

    match(pattern, string, flags=0)
       Try to apply the pattern at the start of the string, returning
       a match object, or None if no match was found.

    意思是必须以符合规则的为开头

    2回答·1958浏览
  • 梦想中的A神 2017-07-30
    \d是什么意思

    试了一下,发现   [1-9]?    这个东西发生是看情况的,需要他发生零次时他就发生0次,需要他发生一次时他就发生一次。

    老师的例子里,这句话没发生作用,

    3回答·2693浏览
  • SuperDi 2017-07-17
    为什么re.match(r'[1-9]?\d$', '09')匹配不到

    我刚看的时候也有这个问题,我是这样理解的,因为表达式中的$决定了它前面的数字(即0)该是被匹配串的最后一位,与事实相悖,所以匹配不到

    2回答·2922浏览
  • Whitney_Wang 2017-06-12
    关于正则表达式中[]的问题
    已采纳 要走心 的回答

    可以这么用,看个人习惯,前者可读性稍微好一些

    1回答·1546浏览
  • 慕丝3583584 2017-05-12
    \<number>的问题

    \1代表第一个分组所引用的内容,改为要下语句:ma=re.match(r'<([\w]+>)\1','<book>book>')

    1回答·909浏览
  • 慕粉0220183176 2017-04-09
    正则表达式$与\Z的区别

    多行问题

    1回答·1816浏览
  • lifelegendc 2017-02-12
    ^的用法!!

    首先,^放在[...]里边才会表示反义,例如[^a]表示匹配除了a以外的字符,如果^放在[]外面,则表示以[...]字符为开头

    还有在[...]中不需要使用“|”表示或的关系,[...]中的“|”被认为需要匹配“|”这个字符

    3回答·1009浏览
  • 锅锅爱吃肉 2017-01-25
    问题~~~
    已采纳 流沙河矿工 的回答

    Hello,我试了一下,其实是这样的:

    正则表达式是从前往后一个一个字符匹配,如果走完了你的正则表达式,没出现问题,就返回匹配值。

    比如r'[abc]',它匹配abc字符中的一个,'ab'中匹配完a之后,正则表达式运行完毕,没有问题,返回了a,结束。

    但是在r'{[abc]}'中,先匹配了{,然后匹配abc中的一个,在你的例子里是a,然后匹配}却匹配不到,因为你的字符串里这时是'b}',它匹配},找到了b,认为有问题,直接匹配就不成功了。

    不不妨尝试ma=re.match(r'{[abc]','{ab}'),这样能返回匹配结果'{a',即一个{加上abc中的一个字母。

    希望我解释清楚了,如果不明白可以问我。

    1回答·987浏览
  • cc在哪 2016-10-24
    正则表达式^和\A的区别 $和\Z的区别
    已采纳 慕粉3936973 的回答
    public static void main(String[] args) { 
            String matcherStr = "This is the first Java";
            matcherStr += "\nAnd";
            matcherStr += "\nThis is the second Python";
            Matcher matcher = Pattern.compile("Java$", Pattern.MULTILINE).matcher(matcherStr);
            
            int i=0;
            while(matcher.find()){
               i++;
            }
            System.out.println(i);
    }

    There is one match (i=1) for Java in the first line. This is mutiline, so the whole matcherStr is something like:

    This is the first Java

    And

    This is the second Python


    public static void main(String[] args) { 
            String matcherStr = "This is the first Java";
            matcherStr += "\nAnd";
            matcherStr += "\nThis is the second Java";
            Matcher matcher = Pattern.compile("Java$", Pattern.MULTILINE).matcher(matcherStr);
            
            int i=0;
            while(matcher.find()){
               i++;
            }
            System.out.println(i);
    }

    There are two matchs (i=2) for Java in the first line. This is mutiline, so the whole matcherStr is something like:

    This is the first Java

    And

    This is the second Java


    public static void main(String[] args) { 
            String matcherStr = "This is the first Java";
            matcherStr += "\nAnd";
            matcherStr += "\nThis is the second Python";
            Matcher matcher = Pattern.compile("Java$").matcher(matcherStr);
            
            int i=0;
            while(matcher.find()){
               i++;
            }
            System.out.println(i);
    }

    There is no match (i=0) for Java. This is not mutiline, so the whole matcherStr is something like:

    This is the first Java\nAnd\nThis is the second Python


    public static void main(String[] args) { 
            String matcherStr = "This is the first Java";
            matcherStr += "\nAnd";
            matcherStr += "\nThis is the second Java";
            Matcher matcher = Pattern.compile("Java\\Z", Pattern.MULTILINE).matcher(matcherStr);
            
            int i=0;
            while(matcher.find()){
               i++;
            }
            System.out.println(i);
    }

    There is one match (i=1) for Java with multiline.  The same as without multiline.

    In this case: If Pattern.compile("Java$", Pattern.MULTILINE), there are two matches.


    public static void main(String[] args) { 
            String matcherStr = "This is the first Java";
            matcherStr += "\nAnd";
            matcherStr += "\nThis is the second Java";
            Matcher matcher = Pattern.compile("Java\\Z").matcher(matcherStr);
            
            int i=0;
            while(matcher.find()){
               i++;
            }
            System.out.println(i);
    }

    There is one match (i=1) for Java without multiline.


    2回答·3423浏览
  • 风语者不语 2016-09-23
    这条字符串为什么匹配不了
    已采纳 慕斯5482594 的回答

    匹配helloworld或者helloworldworld ?  是这个意思吗?

    import re
    
    ma = re.match(r'(hello)(world)\2?', 'helloworld')
    print ma.group()
    ma = re.match(r'(hello)(world)\2?', 'helloworldworld')
    print ma.group()

    把?放在后面

    2回答·1021浏览
  • 徒见楚云空 2016-09-23
    正则表达式

    url是什么?

    2回答·1087浏览
  • 游鱼与渔 2016-09-08
    视频中的‘xmi’是什么意思啊?看到number分组就有点了懵了。求详解
    已采纳 风生水起正好扬帆 的回答

    不是xmi是xml,就是类似于html的标签语言。

    number分组是引用前面的规则,即重复的部分用分组号代替就行,和后面的别名分组类似

    2回答·1382浏览
  • s512831180_rxHPRZ 2016-06-13
    为什么在python2.7.5中出现错误呢
    ma = re.match(r'<([\w]+>)\1','<book>book>')
    print ma.groups()
    print ma.group()

    \1  -->  ([\w]+>)  --> book>    

    你是K大写啊, 当然不匹配,所以是NoneType啊

    2回答·1021浏览
  • alex1650 2016-05-18
    为什么ma = re.match(r'\d$','09') 这样不对呢
    已采纳 dejm 的回答

    大概是因为re.match方法是从字符串开头匹配,如果用re.search可以匹配到9。

    3回答·1117浏览
  • guihailiuli 2016-03-09
    为什么\Z就匹配出错了?
    3回答·1090浏览
数据加载中...
开始学习 免费