" ^ " regular position



  • Just a question. Which means regular "a^b" And can she be found in any line?

    import re
    p = re.compile("a^b")
    p.search("ab") --> None
    p.search("a^b") --> None
    p.search("a\nb") --> None
    

    If such expression does not correspond to any line (actually as the symbol may be) a To meet you. before Why is it even compiled?

    Or, rephrasing, if the meaning of the symbol changes. ^/$ Depending on its situation in regular terms (not in square brackets)? If not, why?

    The question is irrelevant, python is just an example.



  • ^ means "start line," no matter what part of the expression I met. Just like I did. $ - End of the line. But the "start" and "finishes" in the line might be a little bit. Let's take an example.

    import re
    p=re.compile("a.*^b",re.M+re.S)
    p.search("abc\nabcd")  --> None
    p.search("abc\nbcd")   --> <_sre.SRE_Match object; span=(0, 5), match='abc\nb'>
    

    When compiling the expressions, flags are indicated: re.S Makes it. . conform to any symbols, including the translation of the carriage. re.M Makes you look like a row, like a little fast, that is. ^ starting to match not only the data start, but also the point after any transfer of the carriage. So we got that "a" meeting. before starting the line.

    Flags can be applied not only to the second dimension of the compilation, but also within the regular itself, designs like (?sm)♪ I think it's the wrong of the regulars to perform such a deep analysis. In fact, no one's at risk. ^ и $ differently depending on the situation (except square brackets, of course).

    https://regex101.com/r/tY3aJ6/1


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2