PHP » PYTHON |
login |
register |
about
|
PYTHON preg_split
is this article helpful?
|
Python replacement for PHP's preg_split
[
edit
| history
]
import re result = re.split(pattern, subject) result = re.split(pattern, subject, limit) preg_split(PHP 4, PHP 5) preg_split — Split string by a regular expression Description
array preg_split
( string $pattern
, string $subject
[, int $limit= -1
[, int $flags= 0
]] )
Split the given string by a regular expression. Parameters
Return ValuesReturns an array containing substrings of subject split along boundaries matched by pattern . Changelog
Examples
Example #1 preg_split() example : Get the parts of a search string
<?php
Example #2 Splitting a string into component characters
<?php
Example #3 Splitting a string into matches and their offsets
<?phpThe above example will output:
Array
(
[0] => Array
(
[0] => hypertext
[1] => 0
)
[1] => Array
(
[0] => language
[1] => 10
)
[2] => Array
(
[0] => programming
[1] => 19
)
)
NotesTip
If you don't need the power of regular expressions, you can choose faster (albeit simpler) alternatives like explode() or str_split(). See Also
|
more
Recently updated
more
Most requested
more
Last requests
|