Pattern for last 7 digits


(banupriya) #1

I am expecting java regular expression to get the last 7 digits from right side. For Ex the values are in an array : [8765667 097666899]. I need to tokenize "7666899" values for search. I am trying with this pattern
"pattern": "[0-9]{7}",
and not able to get exact results


(Daniel Mitterdorfer) #2

Hi @banu,

more of a Java question than an Elasticsearch question, isn't it? :slight_smile:

There is no need for regexes:

public class Scratch {
    public static void main(String[] args) {
        String[] values = {"8765667", "097666899"};
        for (String value : values) {
            if (value.length() >= 7) {
                addToIndex(value.substring(value.length() - 7));
            } // else: Drop all values that are shorter than 7 characters

        }
    }

    public static void addToIndex(String v) {
        // implement me
        System.out.println("Adding [" + v + "] to index.");
    }
}

Daniel


(banupriya) #3

we need it through sense plugin not through java


(Daniel Mitterdorfer) #4

Hi @banu,

would you mind to provide a full reproducible example with a little data set then that shows in more detail what you are trying to achieve?

Daniel


(system) #5