Regular Expressions 101

Community Patterns

Extract the only the Nth field from a delimited string

1

Regular Expression
PCRE (PHP <7.3)

/
\A(?:[^\|]+\|){2}\K(?P<foo>[^\|]*)
/
g

Description

The aim of this regex is to extract only the Nth field from a delimited string.

In the example provided the delimited is the pipe character.

You will have to substitute the pipe character for whatever delimiter you are using.

Submitted by 0jag - 7 years ago