1

I have something like this in my code:

cust.main.city

I need to find all such occurrences where it has atleast 2 dots I mean references.

So i tried this

[].+.[].+

but it also gave me :

cust.Res;

I only want those lines which has atleast 2 dots (.) in it so I can check further.

Request you to please guide me.

Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476
Prashant
  • 21
  • 6

2 Answers2

0

Have you tried back slash escape for the period?

import re
pattern = r"^\w+\.\w+\.\w+$"
re.match(pattern, "cust.main.city")
Luv
  • 434
  • 4
  • 11
0

Your [].+.[].+ regex is a misleading pattern. It matches a single char from a [].+.[] character class (that is, ], ., + and [) and then matches 1 or more chars other than newline chars (i.e. the rest of the line).

You may match those entities with

\w+(?:\.\w+){2,}

Details

See the regex demo.

Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476