0

Short question: How do I match strings (words) like this:

string_1 = 'e.V.'

string_2 = 'Kaufmann e.K.'

I have tried the following regex:

regex_string_1 = r'(\be.V.\b)'
regex_string_2 = r'(\bKaufmann e.K.\b)'

See demo

I don't know how to handle the dots. I tried multiple different ways. Nothing worked!

PParker
  • 1,419
  • 2
  • 10
  • 25
  • 1
    Just as usual, use unambiguous word boundaries, `(?<!\w)` and `(?!\w)`, or whitespace boundaries, `(?<!\S)` and `(?!\S)`. If they do not work for you, please update the question. – Wiktor Stribiżew Oct 22 '20 at 13:36
  • Thank you very much. That works! – PParker Oct 22 '20 at 13:40
  • 1
    FYI only: As is, the full stops in both your expressions will match *any* character! It will not influence your current test string results because the full stops in there also count as "any character" but you may want to escape the ones in the regex so they must match exactly. – Jongware Oct 22 '20 at 13:57

0 Answers0