Questions tagged [preg-split]

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

550 questions
0
votes
4 answers

Retain Delimiters when Splitting String

Edit: OK, I can't read, thanks to Col. Shrapnel for the help. If anyone comes here looking for the same thing to be answered... print_r(preg_split('/([\!|\?|\.|\!\?])/', $string, null, PREG_SPLIT_DELIM_CAPTURE)); Is there any way to split a string…
JoeC
  • 327
  • 2
  • 3
  • 9
0
votes
1 answer

How to not spliting specific format with the use of regex?

Currently I have a list of string like this "banana、xx、tyu、fdg dfgdf、dfgfdgd、dfdfg、dfgdg 、cvbcvb", dfdgd sdfs. 2te. 459,202' dfg/ dfg, bvn, bn, wqe。uyo. yuo, "yuouy、yuoy、jlkj、nmj , tryrt、346,457、gh、325352 、fghfg" When I use this RegEx :…
user3571945
  • 184
  • 1
  • 14
0
votes
1 answer

PHP preg_split("/[.,] \s /", $content) invalid argument passed

I am trying to split a variable that holds an articles content. I want to loop through it to find keywords but I want to break up the content into an array. preg_split("/[.,] \s /", $content); So what I am doing here is splitting the content based…
Shinerrs
  • 129
  • 2
  • 13
0
votes
3 answers

preg_split get delimiters in an array

Is it possible when using preg_split to return the delimiters into an array in the order that they were found? So take this for example: $string = "I>am+awesome"; preg_split("/>|\+/", $string); and then get an output somewhat like this: Array( …
Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
0
votes
3 answers

preg_split unexpected behavior

I use preg_split as the following:
SaidbakR
  • 13,303
  • 20
  • 101
  • 195
0
votes
2 answers

split string when any numbers occur for the first time

I have a variable that looks like this: $price_string = ' - £55.00'; Is it possible to split this string variable into two variable, at the first occurrence of any number? For example, the above will be $result[0] = ' - £'; $result[1] =…
Latheesan
  • 23,247
  • 32
  • 107
  • 201
0
votes
1 answer

I want to split a string with preg_split and surround the results

I am trying to split a string with preg_split, take the results, surround them with custom data, and reinsert them into the original string. For example: $string="this is text [shortcode] this is also text [shortcode2] this is text"; Afterwards, I…
gregpress
  • 143
  • 1
  • 8
0
votes
0 answers

preg_split regex lookback for multiple matches

The goal of my regex is to split on any unicode whitespace, excluding newline and ensure that that newline character is appended to the previous non unicode whitespace character. Currently I am seeing this work, but only for single whitespace…
Drew
  • 127
  • 2
  • 10
0
votes
1 answer

preg_split regex for splitting on a range but retaining some of that range as the string suffix

Working on the text: This is some text which I am working on. This text has whitespace before the new line but after this word Another line. I am using preg_split to split on the unicode whitespace and all special characters excluding newline…
Drew
  • 127
  • 2
  • 10
0
votes
2 answers

Split a sentence with HTML into words (but leave inline HTML intact)

I am looking for a way to use javascript for splitting a sentence with HTML into words, and leaving the inline HTML tags with the text content intact. Punctuation can be regarded as a part of the word it is closest to. I'd like to use regex, and…
Jeroen
  • 345
  • 3
  • 17
0
votes
2 answers

Need help using explode, preg_match

I have over one thousand reviews in a string. I have been asked to see if i can get the average rate from each author. an example of the string is below. I have highlighted the content which I need to extract into an array. Shepherd's Bush Empire…
gareth
  • 179
  • 2
  • 18
0
votes
3 answers

PHP remove the word directly after another in string

I am coding a search engine.Basically, if a certain word occurs I need the word immediately after that word to be grabbed and removed. If the word 'yoga' occurs, I need to remove the word right after it, here 'mats'.So I would get: $sentence="I like…
Tim
  • 63
  • 1
  • 1
  • 10
0
votes
1 answer

PHP, identify dates and week days in strings

I am trying to identify dates in some strings and the day of week and put the data into another array. My problem is that the data comes in array but not in a regular order. Example #1 of data structure: Array ( [3] => In ziua de Duminica…
0
votes
2 answers

RegExp for capturing "headline" trigger words in textarea

I'm trying to write a regexp for a php preg_split to capture certain "headline" like words in a textarea im processing. I want to use the resulting array to improve formatting for the user and create a streamlined look in review posts. $returnValue…
All Bits Equal
  • 731
  • 2
  • 10
  • 26
0
votes
2 answers

I need to find a way explode a specific string that has quotes in it

I'm having serious trouble with this and I'm not really experienced enough to understand how I should go about it. To start off I have a very long string known as $VC. Each time it's slightly different but will always have some things that are the…
Zei
  • 3
  • 5