0

See title. The behavior here is counterintuitive. I think maybe I am missing some flags or something? Why does the regex z not match the string az?

Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • That is correct 'z' does not match with 'az'. If you say '.z' i.e. ` z` then it matches with 'az' lile `re.match(r'.z', 'az')` – Epsi95 Dec 03 '21 at 05:09
  • Your account is over 11 years old and you have 51(!) gold badges, so you ought to know by now that [some research is expected](https://meta.stackoverflow.com/questions/261592) before asking here. In this case, it's as simple as looking at the [documentation](https://docs.python.org/3/library/re.html?highlight=re#re.match) (which is [easy to find](https://duckduckgo.com/?q=python+re+module)); not only is the specific problem called out in the documentation for `re.match`, but it explicitly tells you what you wanted to use instead. – Karl Knechtel Dec 03 '21 at 05:23

1 Answers1

0

The reason is that match only matches the beginning of a string. Must use search to do the thing that match would do in all other programming languages.

Sorry to throw shade at you Python, but you're the odd one out here.

Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • Messes me up every time. . . . – Frank Yellin Dec 03 '21 at 05:19
  • Given that you've answered your own question here and used language like "throw shade", it comes across like your question and answer are really a thinly disguised rant. Please [do not use Stack Overflow for this purpose](https://stackoverflow.com/help/dont-ask), even given that it's okay to answer your own questions. Design decisions are made for a reason, and naming things is hard. Python's names make more sense to me. – Karl Knechtel Dec 03 '21 at 05:26