Regular Expressions 101

Community Patterns

Use capturing groups to grab CSV columns

1

Regular Expression
PCRE (PHP <7.3)

/
(^[^;]+)(.*)(?:;)(.*$)?
/
gm

Description

This regex gets the first, the last and the middle part as capturing groups and matches the trailing semicolon as a non-capturing group. This allows you to resort CSV columns.

Submitted by Unkulunkulu - 8 years ago