1

Is there something that I can use to search for object patterns in an list or array of objects instead of characters in a string?

I mean search if there is a match where you find object1 one time followed by 3 times object 2. Similar to the way we use it for strings.

4
  • Regular expressions are for strings only. For your problem there is different solutions. For small set of data I would simply use a for-loop. Commented Jul 13, 2019 at 7:02
  • It will get more complex. And I really don't like the idea to write something like RegEx be myself. Commented Jul 13, 2019 at 7:12
  • What about Selecting each object to a char, transforming the list of objects into a string? Commented Jul 13, 2019 at 7:30
  • 2
    That's an option. Currently planning to build an "RegEx" for objects myself. Commented Jul 13, 2019 at 9:12

1 Answer 1

2

So you want to find patterns based on the type of objects in an array. You could turn the list into a string with a character for each object, use regex to get a Match, then return the object at the Match's index.

Sign up to request clarification or add additional context in comments.

2 Comments

It's not only the type, but also the values of some properties. But it might be a possibility.
In a very generic sense, you can turn your array of objects to JSON, then regex that, only it will take some effort to turn that match back to your original object. If you convert each object into a same length character string, then you can use division to find your original item. Having a unique id for each object would work for the JSON option, I guess...

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.