-1

there is such a line

#40: dfgdfhfg fgh dfg hfdgh fghdfg hfdg : dfghdfgh / fghdfgh fdghdfg fghdfghd ghdfghf (just as an example)

how can you separate it with a regular expression like this -

[0] => 40
[1] => dfgdfhfg fgh dfg hfdgh fghdfg hfdg : dfghdfgh / fghdfgh fdghdfg fghdfghd ghdfghf (just as an example)

using preg_split thanks in advance

2
  • 2
    What's the rule you're using to split it? One example is not nearly enough to discern the pattern reliably. Commented Jan 11, 2020 at 22:31
  • It looks like first line is extracting the number between # and : and the second line is the rest after the input string after the first : Commented Jan 12, 2020 at 1:09

1 Answer 1

2

I'm not sure if what you want can be done using preg_split but you can do it with preg_match like this:

$s = "#40: dfgdfhfg fgh dfg hfdgh fghdfg hfdg : dfghdfgh / fghdfgh fdghdfg fghdfghd ghdfghf (just as an example)"    
preg_match('/^\#([0-9]+)\:\s(.*)$/', $s, $matches);

And the two parts you are after will be in $matches[1] and $matches[2]

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, what you need

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.