221
Views
4
Comments
Solved
How to get list of occurrences from regex_search

Currently I am working on regex_search and it works fine. I can get the matched data but I only getting the first occurrence of the matched data. Is it possible to get list of all the occurrences using regex_search? Or if there is some other way to do it?

2026-01-03 13-44-38
Erwin van Rijsewijk
Champion
Solution

If your search succeeded you get the FirstIndex returned.

With the SUBSTR function you kan create a substring,  only containing the part from FirstIndex to the end. On that part you can do a Regex_Search again. Repeat these steps until Regex_Search does not find anything anymore.


2020-11-25 10-45-32
Mostafa Othman
Champion

Regex_Search will return first occurrence only. I may suggest to use String_Split using your pattern so it will split text and return list of which will helps you to know number of occurrence of your pattern.

You can find more details about String_Split here

2022-12-09 04-50-17
Shubham Doshi

1. Split the string using Substr() function.

2. Apply Regex_Search for every element from the string

3. Store the FirstIndex returned into a structure or entity

4. Then you will have the count of occurrence of the matched data

UserImage.jpg
eutat yap

Thanks guys for your quick response. Much appreciated!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.