ISSUE: Listing names that only start with a specific letter / Replacing current value with a new, random value

As the title suggests, I’m trying to get names that only start with the letter I wish to specify.

Here is the code I’ve been using (in reference to the “First Name” Mockaroo data set):

while this[0,1] != ‘P’
this = [:first_name:]
end

I end up with a syntax error, and it is probably due to the fact that I don’t know how to use regex properly.

I have also tried doing the following, instead of the regex:

this = from_dataset(“Personal”, “First Name”, ‘P’ : first_name[0,1])

^ That didn’t work either, since I’m thinking the ‘P’ : first_name[0,1] bit doesn’t ever change value, and so a new name isn’t chosen, and an infinite loop gets created. Any light on this subject would be quite nice. Thanks in advance!

EDIT: As clarification, what I am trying to accomplish is being able take the current given value (in this case, it would be the result from mockaroo’s “First Name” list) and replace it with another value from that same list. Or, as an alternative, create a subset of the list that follows a restriction (in this case, all names must start with P).

You’re on the right track with the second approach. The problem is that from_dataset only supports filtering by exact match, not regex. One way to do it would be to create a new dataset that has a separate “first_letter” column containing the first letter of the name (which you could compute using a formula if you’re creating the dataset using Mockaroo). Then you would have a way to look up names by first letter.

Hmm, I must still be doing something wrong then, since I am going into an infinite loop, I believe.
Here is the link for reference: https://www.mockaroo.com/6d1b7ba0

So, I created a new dataset, as suggested, and named it “first_letter” with the restriction in the formula field being [this = ‘P’] (without the brackets), so that all entries in “first_letter” would be P.

I then went to the other dataset, “first_name”, and tweaked the formula for it as such:

while this[0,1] != ‘P’
this = from_dataset(“Personal”, “First Name”, first_letter[0,1]: first_name[0,1])
end

Unfortunately, instead of grabbing a name that starts with P, it goes into an infinite loop.

EDIT: I also see why the regex wasn’t working - it was due to the fact that I didn’t realize you created a special regex database, and I was just trying to use it as part of the formula for a dataset. Once I realized that, I tried to use a formula for the regex dataset, but that didn’t work (since the normal logic couldn’t be evaluated alongside the regex, I think?).

EDIT2: Thinking over the function, and your reply, a bit more, are you suggesting I populate a new dataset (or 2) with random names from the mockaroo list, and then select the name that starts with the desired letter from there? / have those random names insert their first letter into another dataset, and from there be able to somehow grab the names that start with the desired letter from the first dataset?

Well, I couldn’t figure how to achieve what I wanted, so I just uploaded a dataset with something akin to what I wanted. However, I still am curious if there is a way to do this, using only what Mockaroo has to offer, in terms of lists.