Question: I have a variable (year) which is all 2007 and 2008s but I need to change it into a factor so it reads 0 and 1s. Is there a way to do this?

So it can be used in a general linear model

Answer: 
`/^([^|]+)\|(?:[^|]+\|)*?\K[^|]*\b\1\b[^|]*/`

It is important to capture the needle and at minimum use wordboundaries when searching for its next occurrence.

Also, it is important to enable a match as the first, middle or last data set in the string. This is the importance of `(?:[^|]+\|)*?`

Demo: <https://regex101.com/r/7lMwZf/5>

Breakdown:

```
^                     # start of string
([^|]+)\|             # capture needle then match first delimiting pipe
(?:[^|]+\|)*?         # match zero or more "sets of data"
\K[^|]*\b\1\b[^|]*    # forget previously matched characters with \K, then match set of data containing the needle until the end of string or first encountered pipe

```
Here is a pattern which seems to be working:

```
(?<=\||^)((?:(?!\|).)*Interface123.*?)(?=\||$)

```

This uses tempered dots to match the segment of the string you want, containing `Interface123`. Here is a brief explanation:

```
(?<=\||^)       assert that what is prior is either pipe or the start of the string
((?:(?!\|).)*   consume anything so long is it is NOT pipe
Interface123.*? match 'Interface123` followed by anything up to
(?=\||$)        assert that what follows is either pipe or the end of the string

```

[Demo
----](https://regex101.com/r/nK4Sos/1)

This answer uses lookarounds, but based on your comment that your regex flavor is Perl compatible, this should not be a problem.