You need to escape the |
symbol in regular expressions otherwise it means alternation. It's also a good idea to use anchors if you are in doubt as to whether or not they are required for your regular expression library. This expression matches anything that contains 1 in the id:
^.*1.*\|.*\|.*\|.*$
To match id = 1 exactly, change it to this:
^1\|.*\|.*\|.*$
To match name = 'Foo' exactly:
^.*\|Foo\|.*\|.*$
A good point raised in the comments is that it would be good to use [^|]*
instead of .*
to ensure that the data has the correct number of pipe symbols.
Note that regular expressions will be a slow way to find your data if you need to make many lookups. It would be faster to first parse the data and then to keep them stored in data structures that allow you to make fast lookups, such as a hash table.