Filter on UUID

Options

Hi!

I have an array of keys, some of which are UUID's, others some other type (ex.: md5).

What would be the best method to filter out / retain only the UUID's in that array?

Thank you

Best Answer

  • MattLaro
    MattLaro Member ✭✭
    Answer ✓
    Options

    It's weird…for some reason, my comment got erased. Here we go again !

    Did you try the UUID regexp ?

    /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/

    Results

    Note : You MUST store your regexp in a variable. including the regexp directly in the condition's input doesn't seem to work.

    Hope it helps!

Answers

  • Gi Ma
    Gi Ma Member
    Options

    I've found a temporary workaround (not solution):

    Array, find all elements, length=36

    However, this is not the cleanest/best way to do it.

    Any better ideas?

  • MattLaro
    MattLaro Member ✭✭
    Options

    Did you try using the UUID regexp pattern ?

    /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/


    Result

    my_array :

    Note : You MUST store your regexp expression in a variable. Using directly in the condition won't work.

    Hope it helps!

  • Gi Ma
    Gi Ma Member
    Options

    Thank you @MattLaro , this worked perfectly!🙌