1

I have recently began learning q programming language and I find it a little bit of a struggle since I am coming from the 'traditional' imperative, OOP, etc language background. I am trying to perform a seemingly simple task - find strings in list that contain specific character:

names:("Saint Denis";"Rhodes";"Strawberry";"Valentine")

How do I print all strings that contain letter "R"? Even better, both "R" and "r"?

The furthest I was able to get is this:

{[x]x?"o"} each names

What would be the correct approach?

Thanks in advance!

3 Answers 3

7

You could use the like keyword with a regular expression like so:

q)names where names like "*[Rr]*"
"Rhodes"
"Strawberry"
Sign up to request clarification or add additional context in comments.

Comments

3

You could use something like the below

q)names where "R" in/: names
"Rhodes"
q)names where any each "rR" in/: names
"Rhodes"
"Strawberry"

Comments

3

Another couple of alternatives are:

q)names where "r" in'lower names
"Rhodes"
"Strawberry"

q)names where any"Rr"in'\:names
"Rhodes"
"Strawberry"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.