久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <small id='DXqpj'></small><noframes id='DXqpj'>

    2. <tfoot id='DXqpj'></tfoot>

        • <bdo id='DXqpj'></bdo><ul id='DXqpj'></ul>
      1. <i id='DXqpj'><tr id='DXqpj'><dt id='DXqpj'><q id='DXqpj'><span id='DXqpj'><b id='DXqpj'><form id='DXqpj'><ins id='DXqpj'></ins><ul id='DXqpj'></ul><sub id='DXqpj'></sub></form><legend id='DXqpj'></legend><bdo id='DXqpj'><pre id='DXqpj'><center id='DXqpj'></center></pre></bdo></b><th id='DXqpj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='DXqpj'><tfoot id='DXqpj'></tfoot><dl id='DXqpj'><fieldset id='DXqpj'></fieldset></dl></div>
        <legend id='DXqpj'><style id='DXqpj'><dir id='DXqpj'><q id='DXqpj'></q></dir></style></legend>

        Python 2.6+ str.format() 和正則表達式

        Python 2.6+ str.format() and regular expressions(Python 2.6+ str.format() 和正則表達式)
          <i id='ef4x3'><tr id='ef4x3'><dt id='ef4x3'><q id='ef4x3'><span id='ef4x3'><b id='ef4x3'><form id='ef4x3'><ins id='ef4x3'></ins><ul id='ef4x3'></ul><sub id='ef4x3'></sub></form><legend id='ef4x3'></legend><bdo id='ef4x3'><pre id='ef4x3'><center id='ef4x3'></center></pre></bdo></b><th id='ef4x3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ef4x3'><tfoot id='ef4x3'></tfoot><dl id='ef4x3'><fieldset id='ef4x3'></fieldset></dl></div>

            <tbody id='ef4x3'></tbody>

            <small id='ef4x3'></small><noframes id='ef4x3'>

          1. <tfoot id='ef4x3'></tfoot>

                <bdo id='ef4x3'></bdo><ul id='ef4x3'></ul>

                • <legend id='ef4x3'><style id='ef4x3'><dir id='ef4x3'><q id='ef4x3'></q></dir></style></legend>
                  本文介紹了Python 2.6+ str.format() 和正則表達式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  使用 str.format() 是 Python 2.6 和 Python 3 中格式化字符串的新標準.使用 str.format() 時遇到問題code> 帶有正則表達式.

                  Using str.format() is the new standard for formatting strings in Python 2.6, and Python 3. I've run into an issue when using str.format() with regular expressions.

                  我編寫了一個正則表達式來返回比指定域低一級的所有域或比指定域低兩級的任何域,如果下面的第二級是 www...

                  I've written a regular expression to return all domains that are a single level below a specified domain or any domains that are 2 levels below the domain specified, if the 2nd level below is www...

                  假設指定的域是delivery.com,我的正則表達式應該返回a.delivery.com、b.delivery.com、www.c.delivery.com ...但它不應該返回xadelivery.com.

                  Assuming the specified domain is delivery.com, my regex should return a.delivery.com, b.delivery.com, www.c.delivery.com ... but it should not return x.a.delivery.com.

                  import re
                  
                  str1 = "www.pizza.delivery.com"
                  str2 = "w.pizza.delivery.com"
                  str3 = "pizza.delivery.com"
                  
                  if (re.match('^(w{3}.)?([0-9A-Za-z-]+.){1}delivery.com$', str1): print 'String 1 matches!'
                  if (re.match('^(w{3}.)?([0-9A-Za-z-]+.){1}delivery.com$', str2): print 'String 2 matches!'
                  if (re.match('^(w{3}.)?([0-9A-Za-z-]+.){1}delivery.com$', str3): print 'String 3 matches!'
                  

                  運行它應該會給出結果:

                  Running this should give the result:

                  String 1 matches!
                  String 3 matches!
                  

                  現在,問題是當我嘗試使用 str.format 動態替換 delivery.com...

                  Now, the problem is when I try to replace delivery.com dynamically using str.format...

                  if (re.match('^(w{3}.)?([0-9A-Za-z-]+.){1}{domainName}$'.format(domainName = 'delivery.com'), str1): print 'String 1 matches!'
                  

                  這似乎失敗了,因為 str.format() 期望 {3}{1} 是功能.(我假設)

                  This seems to fail, because the str.format() expects the {3} and {1} to be parameters to the function. (I'm assuming)

                  我可以使用 + 運算符連接字符串

                  I could concatenate the string using + operator

                  '^(w{3}.)?([0-9A-Za-z-]+.){1}' + domainName + '$'
                  

                  問題歸結為,當字符串(通常是正則表達式)中包含{n}"時是否可以使用str.format()?

                  The question comes down to, is it possible to use str.format() when the string (usually regex) has "{n}" within it?

                  推薦答案

                  您首先需要格式化字符串,然后使用正則表達式.將所有內容放在一行中確實不值得.轉義是通過加倍花括號來完成的:

                  you first would need to format string and then use regex. It really doesn't worth it to put everything into a single line. Escaping is done by doubling the curly braces:

                  >>> pat= '^(w{{3}}.)?([0-9A-Za-z-]+.){{1}}{domainName}$'.format(domainName = 'delivery.com')
                  >>> pat
                  '^(w{3}\.)?([0-9A-Za-z-]+\.){1}delivery.com$'
                  >>> re.match(pat, str1)
                  

                  另外,re.match在字符串的開頭匹配,如果使用re.match就不用放^code>,但是如果您使用 re.search,則需要 ^.

                  Also, re.match is matching at the beginning of the string, you don't have to put ^ if you use re.match, you need ^ if you're using re.search, however.

                  請注意,正則表達式中的 {1} 相當多余.

                  Please note, that {1} in regex is rather redundant.

                  這篇關于Python 2.6+ str.format() 和正則表達式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)

                      • <i id='4KieT'><tr id='4KieT'><dt id='4KieT'><q id='4KieT'><span id='4KieT'><b id='4KieT'><form id='4KieT'><ins id='4KieT'></ins><ul id='4KieT'></ul><sub id='4KieT'></sub></form><legend id='4KieT'></legend><bdo id='4KieT'><pre id='4KieT'><center id='4KieT'></center></pre></bdo></b><th id='4KieT'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4KieT'><tfoot id='4KieT'></tfoot><dl id='4KieT'><fieldset id='4KieT'></fieldset></dl></div>

                          <tbody id='4KieT'></tbody>
                        <tfoot id='4KieT'></tfoot>
                        <legend id='4KieT'><style id='4KieT'><dir id='4KieT'><q id='4KieT'></q></dir></style></legend>
                          <bdo id='4KieT'></bdo><ul id='4KieT'></ul>

                          <small id='4KieT'></small><noframes id='4KieT'>

                            主站蜘蛛池模板: 久热久热 | 亚洲视频中文字幕 | 91成人免费电影 | 中文字幕视频一区 | 精品一二三 | 国产精品资源在线 | 特级毛片爽www免费版 | 日韩av成人| 特级做a爰片毛片免费看108 | 午夜影院在线观看 | 青青草华人在线视频 | 国产精品久久久久久久久动漫 | 日韩国产精品一区二区三区 | 久久精品这里精品 | 蜜臀91视频 | 免费观看一级特黄欧美大片 | 亚洲一区二区综合 | 精品一区二区久久久久久久网站 | 亚洲欧美男人天堂 | 欧美日韩一区二区在线播放 | www.欧美视频 | 中文字幕精品一区 | 亚洲三区在线 | 日本不卡在线观看 | 日韩国产高清在线观看 | av毛片 | 国产精品免费一区二区三区四区 | 日本久久网 | 黄色在线免费观看 | 亚洲精品久久久久avwww潮水 | 亚洲视频中文字幕 | 偷牌自拍 | 狠狠干网| 日韩视频中文字幕 | 欧美日韩国产精品激情在线播放 | 这里精品 | 九九免费观看视频 | 亚洲视频一区二区三区 | 一色桃子av一区二区 | 亚洲激情一区二区三区 | 国产精品久久久久久238 |