代码之家  ›  专栏  ›  技术社区  ›  Toothpick Anemone

字母“i”本身的正则表达式是什么?

  •  2
  • Toothpick Anemone  · 技术社区  · 1 年前

    在下面的英语句子中,字母 i 没有正确大写。

    with this notice know that i inscribe messages to inform.
    a boy named "Will" said into a microphone that time is like a high-five.
    i give lines to computers to find cities and sites. 
    i am my eyes, and to view is to exist (cuanda tu ve, tu comprendes el significado del 'hay')
    view that i will not be processing your application any further because i am eating an apple.
    
    --------------------------------------------------------------------------------
    wIth thIs notIce know that I InscrIbe messages to Inform.
    a boy named "WIll" saId Into a mIcrophone that tIme Is lIke a hIgh-fIve.
    I gIve lInes to computers to fInd cItIes and sItes. 
    I am my eyes, and to vIew Is to exIst (cuanda tu ve, tu comprendes el sIgnIfIcado del 'hay')
    vIew that I wIll not be processIng your applIcatIon any further because I am eatIng an apple.
    

    哪种python脚本可以找到这封信 当它不在另一个词的内部时?

    我们可能想构建一个 regular expression 使用regex库(名为 re ).

    这个 dea s到 忽略这封信 当信件 发生 较大单词的nside。

    我们w sh定位字母 当信件 孤立的和/或用作f 第一人称单数代词。

    什么python脚本w ll正确加盖 将字母大写” ”,对文本不做任何其他操作?

    1 回复  |  直到 1 年前
        1
  •  3
  •   user24714692    1 年前

    你可以使用单词边界( \b )和re() \bi\b 图案

    import re
    
    s = """with this notice know that i inscribe messages to inform.
    a boy named "Will" said into a microphone that time is like a high-five.
    i give lines to computers to find cities and sites. 
    i am my eyes, and to view is to exist (cuanda tu ve, tu comprendes el significado del 'hay')
    view that i will not be processing your application any further because i am eating an apple.
    
    --------------------------------------------------------------------------------
    wIth thIs notIce know that I InscrIbe messages to Inform.
    a boy named "WIll" saId Into a mIcrophone that tIme Is lIke a hIgh-fIve.
    I gIve lInes to computers to fInd cItIes and sItes. 
    I am my eyes, and to vIew Is to exIst (cuanda tu ve, tu comprendes el sIgnIfIcado del 'hay')
    vIew that I wIll not be processIng your applIcatIon any further because I am eatIng an apple.
    """
    
    print(re.sub(r'\bi\b', 'I', s))
    

    打印

    with this notice know that I inscribe messages to inform.
    a boy named "Will" said into a microphone that time is like a high-five.
    I give lines to computers to find cities and sites. 
    I am my eyes, and to view is to exist (cuanda tu ve, tu comprendes el significado del 'hay')
    view that I will not be processing your application any further because I am eating an apple.
    
    --------------------------------------------------------------------------------
    wIth thIs notIce know that I InscrIbe messages to Inform.
    a boy named "WIll" saId Into a mIcrophone that tIme Is lIke a hIgh-fIve.
    I gIve lInes to computers to fInd cItIes and sItes. 
    I am my eyes, and to vIew Is to exIst (cuanda tu ve, tu comprendes el sIgnIfIcado del 'hay')
    vIew that I wIll not be processIng your applIcatIon any further because I am eatIng an apple.