I want to split the content of a text file by ;
and :
:
#STA:00007;TM:01/30/2016,13:48:03;
Desired output:
STA TM
00007 01/30/2016,13:48:03
This should separate your values.
preg_match('/^#STA:(\d+);TM:([\d\/:,]+);$/', '#STA:00007;TM:01/30/2016,13:48:03;', $matches);
$sta = $matches[1];
$tm = $matches[2];
Regex101 Demo: https://regex101.com/r/zH7gL9/1
PHP Demo: https://eval.in/515351
If that part is in the middle of a string take out the anchors ^$
.
\d
is a number 0-9
.+
is a quantifer meaning 1 or more of the preceding character/group/class.[]
is a character meaning the characters inside are allowed.^$
are anchors, matching the start and end of the string./
s are delimiters.()
are capture groups (what is inside is captured).
Everything else in that regex is literal.