1

I have string like this 125.67.888.66.123. I want to count number of dot operations.

For example:

123.45 => 2

3446.67.88 => 3

23.45.567.88 => 4

I write this query SELECT REGEXP_COUNT ('3.222.123.44.1055', '.') FROM dual;

But it gives 16.How can i obtain 5 for above query.When i find exact number I will start a loop.Do you have any idea?

tom
  • 215
  • 3
  • 11
  • Does this answer your question? [What special characters must be escaped in regular expressions?](https://stackoverflow.com/questions/399078/what-special-characters-must-be-escaped-in-regular-expressions) – Ryszard Czech Nov 09 '20 at 20:43

2 Answers2

2

You need to escape . -- and to add 1:

SELECT REGEXP_COUNT('3.222.123.44.1055', '[.]') + 1
FROM dual; 
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

Like said Gordon, you need to escape the dot, because it's a special char in a regex.

But I'm not agree with the regex, to escape you have to use a backslash.

SELECT REGEXP_COUNT('3.222.123.44.1055', '\.') +1 
FROM dual;
Pedro
  • 21
  • 6