Questions tagged [preg-split]

preg_split() is a PHP function which allows splitting a string using a regular expression.

550 questions
2
votes
1 answer

How to split repeated chars and numbers with preg_split?

I'm trying to solve some problem and I need to split repeated chars and all integers $code = preg_split('/(.)(?!\1|$)\K/', $code); I tried this one, but it separate and not repeated chars and not repeated integers , I need only chars I have a…
2
votes
1 answer

Is there a way to replace some quotation marks with preg_split and to leave some out?

I'm trying to use preg_split() but the results aren't what I expect to get from the function. I'm new to php and the whole preg_split() scene and it seems to complicated for me to understand, at least for the moment. $row =…
2
votes
3 answers

preg_split : splitting a string according to a very specific pattern

Regex/PHP n00b here. I'm trying to use the PHP "preg_split" function... I have strings that follow a very specific pattern according to which I want to split them. Example of a string: CADAVRES [FILM] (Canada : Québec, Érik Canuel, 2009, long…
2
votes
1 answer

PHP: preg_replace only first matching string in array

I've started with preg_replace in PHP and I wonder how I can replace only first matching array key with a specified array value cause I set preg_replace number of changes parameter to '1' and it's changing more than one time anyways. I also splitted…
2
votes
3 answers

php preg_split or explode. Not removing the character

I have been trying several ways to solve my issue and have found a poor work-around, but I would like to know if there is something else out there. I have a string of several sub-strings which are separated by commas. I can split this up into an…
charco
  • 71
  • 6
2
votes
2 answers

Split line into multiple parts using regex

I have a string like BK0001 My book (4th Edition) $49.95 (Clearance Price!) I would like a way to split it into different parts like [BK0001] [My Book (4th Edition)] [$49.95] [(Clearance Price!)] I'm pretty new at regex and I'm using this to…
answerSeeker
  • 2,692
  • 4
  • 38
  • 76
2
votes
1 answer

PHP - How to split string into array by regular expression at whitespace and html tag?

Here is a example string: $string = 'Lorem ipsum dolor sit amet consectetuer.'; I want to split the string into array such that the string get split whenever…
Armaan
  • 73
  • 3
2
votes
2 answers

PHP preg_split IPs in a string

I am trying to use preg_split in PHP to break up the following string and return me the 2 ip addresses: $membersStr = "members { 167.69.27.151:4449 {} 167.69.27.153:4449 {} 167.69.27.154:4449 { session user disabled } 167.67.27.156:4449 }"; My code…
Jim
  • 613
  • 6
  • 16
  • 25
2
votes
4 answers

Split string by last character and save to array?

I have several strings that look like: longname1, anotherlongname2, has1numbers2init3 I would like to use str_split to split off the last character of the strings. Eg: Array ( [0] => longname [1] => 1 ) Array ( [0] => anotherlongname [1] => 2…
MeltingDog
  • 14,310
  • 43
  • 165
  • 295
2
votes
1 answer

How to split string with number(coordinates) in java?

I want split bellow string with numbers means coordinates. Please help me split pattern in java 34°6′19″N 74°48′58″E / 34.10528°N 74.81611°E / 34.10528; 74.81611This is very good place for tour This string I want separate string 1. 34°6′19″N…
2
votes
1 answer

Split a string by forward slash but ignore the <\ in the string

I have string similar to this word1/word2/word3/word3 I want to explode this string by forward slash. So that I can get the following result. Array = ( [0] => 'word1', [1] => 'word2', [2] => 'word3', [3] => 'word3' ); But I'm unable…
Ahmad
  • 2,099
  • 10
  • 42
  • 79
2
votes
3 answers

Regex match exact words

I want my regex to match ?ver and ?v, but not ?version This is what I have so far: $parts = preg_split( "(\b\?ver\b|\b\?v\b)", $src ); I think the trouble might be how I escape the ?.
Fjott
  • 1,107
  • 3
  • 15
  • 38
2
votes
4 answers

How to get everything except brackets from string using php preg_split?

$str = "[10:42-23:10]part1[11:30-13:20]part2" I wish to split it into something like: [1] 10:42-23:10 [2] part1 [3] 11:30-13:20 [4] part2 The best I managed to come up with is: $parts = preg_split("/(\\[*\\])\w+/", $str ); But this returns [0] =>…
gilad s
  • 475
  • 8
  • 16
2
votes
4 answers

preg_split to unknown number of list() elements

I have a PHP script that I wrote probably 10 years ago. I don't remember what version PHP was on at the time but my script worked just fine without complaint from the interpreter. Now, I've had to move my scripts to a new web host and, under PHP…
unclerojelio
  • 435
  • 6
  • 12
2
votes
3 answers

split string with preg_split on english (and non english letters)

I want to separate my sentence(s) into two parts. Because they are made of English letters and non english letters. I have regex I am using in preg_split method to get normal letters and characters. This though, works for opposite and I am left…