555 questions
0
votes
0
answers
31
views
match random lengths of string using regex (preg_match) [duplicate]
i have need to split string, by regex:
split digits together
split letters together
[ each part should contain between 3-5 chars RANDOMLY ]
so if i have:
'...
0
votes
0
answers
25
views
Deprecated: preg_split(): [duplicate]
I have this code for current url:
$core = preg_split('@/@', str_replace($_SERVER['DOCUMENT_ROOT'], '', realpath(dirname(__FILE__))), NULL, PREG_SPLIT_NO_EMPTY);
On php 8.1.x the problem in this line ...
0
votes
0
answers
71
views
Cannot remove whitespace from html file in order to preg split
We receive HTML blood files for clients and I am trying to finish some PHP code to strip, clean and preg strip the code so that I can assemble multiple files into a spreadsheet. The issue is that the ...
1
vote
1
answer
70
views
How can I find a string in a JSON string using a regular expression on PHP?
I have string with hyphens:
$str = `Res TP/1.1 101 Switching Protocols
Upgrade: websocket
Sec-WebSocket-Version: 13
Connection: Upgrade
Sec-WebSocket-Accept: dlnHlWqQ4h57DuALMOjKJmxbNn8=
Server: ...
-2
votes
1
answer
51
views
Split string with PHP piece by piece
I have a string that I want to split like this:
Sinn.und.Sinnlichkeit.1995.German.DL.1080p.BluRay.x264-RSG <--- Original string
Sinn.und.Sinnlichkeit.1995.German.DL.1080p.BluRay.x264 <--- no ...
0
votes
1
answer
77
views
Split text containing numbered lines into array of sentences
How can I convert this numbered paragraph into an array of sentences?
1. The best foods for your cat's diet
2. How to ensure your cat is getting enough nutrients
3. The importance of a balanced diet ...
1
vote
3
answers
84
views
Get values which contain only whitelisted characters from a comma-delimited string
I have an array (converted from a string) that contains words with non-standard letters (letters not used in English, like ć, ä, ü). I don't want to replace those characters, I want to get rid of the ...
0
votes
1
answer
51
views
How to print first two words of a sentence in php
I wanna print the first two words of a sentence,
$txt = "Laravel PHP Node JS";
and expecting the output Laravel PHP
used below snippet is there any other way to simplify it?
echo (implode(...
1
vote
1
answer
67
views
Preg split multi SQL by semicolon in PHP
i am trying split my multi SQL by preg, but it doesn works...
Code:
$multiSql = "
ALTER TABLE `my_table` CHANGE `typ` `typ` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '0=none; 1=test1; 2=test2;...
2
votes
3
answers
140
views
How to group sentences by groups of 500 characters without breaking a sentence with PHP?
I have been scratching my head on this but cannot work out a solution.
Let's say you have a text of 5000 characters, I would like to split it into blocks of less than 500 characters, but, without ...
0
votes
1
answer
63
views
SPLIT Long complicated string [duplicate]
The problem I am having is the string may start with a quote. The pattern is
,<true|false>,,,,,,
Some the numbers with decimals can be negative or positive. The final array I need looks like ...
0
votes
3
answers
269
views
PHP preg_split only inside double quotes
How i can take the value only inside the double quotes with preg_split function
from this example string
$String = '["number","1","2470A K18-901","PEDAL ASSY, GEAR ...
0
votes
3
answers
402
views
Regex to split string by space and number using preg_split in PHP?
I need to split a string by number and by spaces but not sure the regex for that. My code is:
$array = preg_split('/[0-9].\s/', $content);
The value of $content is:
Weight 229.6104534866 g
Energy 374....
0
votes
2
answers
81
views
Split strings in array to form three-element subarrays
I am practising with the AdventureWorks database for now and I will be receiving strings like the following: SalesOrderNumber=SOH123 and CustomerID=1. The strings may not always contain =, as they ...
1
vote
2
answers
327
views
How to match comma outside multiple parentheses by regex
I split a string by comma, but not within parathesis, using preg_split. I came up with
preg_split('#,(?![^\(]*[\)])#',$str);
which works perfectly unless there is a comma before a nested parenthesis.
...
0
votes
1
answer
161
views
Using preg_split() to extract a part of a number on first occurrence of a particular number
I am trying to extract a part of the string 0044800 999999 at the first occurrence of a non-zero. I am using preg_split() thus:
$str = preg_split("/[1-9]/", "0044800 999999", 2);
...
5
votes
4
answers
807
views
Split string on delimiter unless contains in single or double quotes [duplicate]
I have a string like aa | bb | "cc | dd" | 'ee | ff' and I'm looking for a way to split this to get all the values separated by the | character with exeption for | contained in strings.
The ...
2
votes
4
answers
81
views
Split lines of space-delimited values to get flat array of 2nd and 3rd column values
I have the following data which is displaying as this
{123456 123456 123456}
{654321 654321 654321}
{123456 123456 123456}
My PHP Code:
$myarray = preg_split("/(\s|{\s)/", $data);
...
2
votes
1
answer
196
views
arabic characters to ABCD characters
I am working with below code in php to show the arabic letters in roman ABCD characters as defined below in my code.
But it is not displaying properly. It is losing the character sorting also and not ...
1
vote
4
answers
50
views
preg_split returns a non expected number
my first question, so please be patient with me...
I have this string:
"Create a script which will take a string and analyse it to produce
the following stats. Spicy jalapeno bacon ipsum dolor ...
1
vote
1
answer
268
views
Split a log file using preg_split based on dates with PHP?
I have a txt file with this format:
14/12/2020 12:02:50
LOG_HERE_1 XXXXX
14/12/2020 12:04:55
LOG_HERE_2 XXXXX
14/12/2020 12:10:33
LOG_HERE_3 XXXXX
And I need to parse it, using a regexp on the ...
2
votes
2
answers
106
views
Split mathematic expression into array without splitting subexpressions between parentheses and single quotes
Let's say I have this string:
1 + 2 * (3 + (23 + 53 - (132 / 5) + 5) - 1) + 2 / 'test + string' - 52
I want to split it into an array of operators and non-operators, but anything between the () and ' ...
1
vote
2
answers
228
views
PHP preg_split keep special characters inside double quotemarks
I'm using regex in preg_split to split a string into separate parts.
$string = 'text required name="first_name" label="First Name" column="1/2"';
$ps = preg_split("/\...
0
votes
1
answer
86
views
preg_split with array delimiters with comma not split the array
I have an array with a list in an array and I have to split to find next a value
$artista_inserito = 'DEN HARROW';
$tutti_artisti_data_ora = [
['time_artisti' => '18:31:00', 'artista_artisti' =&...
1
vote
3
answers
326
views
Split a string after each wole number
I'm looking for a way to split the following string after each set of numbers using regex. I am fairly new to this and I'm having a hard time understanding how to use the correct regex format.
$...
2
votes
3
answers
954
views
How to Split/Explode a string into a numbered lists in PHP? [closed]
I am trying to split this string into numbered lists..
str options is "Hello,Howdy,Hola".
I need the output to be
Hello
Howdy
Hola
This is my code
$newstr = 'My values are' . explode("...
0
votes
0
answers
982
views
Split an array from URL parameter by comma and space delimiter in php
I'm using a Wordpress plugin called Formidable Forms, but that shouldn't be a hindrance to this question.
There's a PHP Hook (https://formidableforms.com/knowledgebase/frm_setup_new_fields_vars/#kb-...
1
vote
1
answer
85
views
Preg_split matching preset number of instances from right to left
I'm hoping that there's some way in regex to match certain characters by counting from right to left.
I have a text like the one below where the fields are inconsistent, except that they are delimited ...
-2
votes
2
answers
121
views
How to parse a mostly consistent filename into meaningful parts?
I have filenames like:
1234_56_78 A_FAIRLY_SHORT_TITLE_D.pdf
Luckily, the file naming is pretty consistent, but I can't absolutely guarantee that someone didn't use a space where they should have ...
0
votes
2
answers
562
views
Getting key and value from string
<?php
// This is my string
$input = "Lorum ipsum [tag=foo]dolor[/tag] sit [tag=bar]amet[/tag] consectetur adipiscing elit.";
// This is my pattern
$pattern = "~\[tag=(.*?)\](.*?)\[/...
1
vote
1
answer
44
views
PHP pre_split looses first character
I have the following string, and want to split the name from the invoiceid. The name could have a space, and possibly a hyphen as well.
$invoice_id ="May-Ann Jane-28188-1600086909";
$...
0
votes
1
answer
108
views
How to extract regex value from preg_split() function in PHP
If I use preg_split() function for example:
$string = 'products{id,name},articles{title,text}';
$arr = preg_split('/\}\,(\w)/', $string);
print_r($arr);
I receive the following result:
Array ( [0] =&...
1
vote
1
answer
81
views
Wrapping subpattern in square braces does not encapsulate the match as expected in regular expression [duplicate]
Regular exp = (Digits)*(A|B|DF|XY)+(Digits)+
I'm confused about this pattern really
I want to separate this string in PHP, someone can help me
My input maybe something like this
A1234
B 1239
...
0
votes
3
answers
219
views
Split text file in to array using regular expression PHP
I have some changelog text in a string and I would like to split each changelog entry into an array.
Here's an example of the changelog text in a variable - $changelog_txt:
version 4.4.6 ( updated ...
1
vote
1
answer
40
views
How to keep the delimiter in the next item in preg_split?
I split a string by a set of characters as
$str = 'a-1 90 b55 0 -4 4 c9';
$array = preg_split('#(?<=[abc])#',$str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
it preserves the delimiter ...
1
vote
2
answers
199
views
preg_split on regex line start
I'm trying to format the following file;
[30-05-2013 15:45:54] A A
[26-06-2013 14:44:44] B A
[26-06-2013 14:44:44] C A
[26-06-2013 14:43:16] Some lines are so large, they take multiple lines, so ...
0
votes
1
answer
112
views
Preg_split loses foreign letters [duplicate]
I'm trying to use one script for keyword density. Everything works except for foreign letters (be it swedish, Estonian, or anything else).
$file includes the text.
Here's where the problem comes in:
...
2
votes
3
answers
432
views
How to split string by slash which is not between numbers?
How to split string by slash which is not between numbers?
I am using preg_split function below:
$splitted = preg_split('#[/\\\\\_\s]+#u', $string);
Input: "925/123 Black/Jack"
Splitted result now:
...
0
votes
4
answers
286
views
Isolate all words in a string and the number of (multibyte-safe) characters that preceeded each word
I want to use preg_split() with its PREG_SPLIT_OFFSET_CAPTURE option to capture both the word and the index where it begins in the original string.
However my string contains multibyte characters ...
1
vote
3
answers
552
views
I'm doing a preg_split but only obtaining a value on the second value of the array - PHP
Whith this code I'm trying to split a string in the "//" but it only gives me a value on the $splits[1] and on the $splits[0] gives me nothing.
while($row = $result->fetch_assoc()) {
$...
0
votes
0
answers
36
views
How to use preg_split for dividing unsigned numbers? [duplicate]
I have a set of single or pair numbers as
9 (9)
-8 (-8)
1.1-2 (1.1 and 2)
-1-.2 (-1 and 0.2)
-1--3 (-1 and -3)
1--2 (1 and -2)
I want to split them to an array of two elements, as the second element ...
0
votes
0
answers
41
views
Regex that matches a string between square brackets except inside a specific html tag [duplicate]
I'm looking for a regex that matches between square braces but ignores input values.
Here is my current code:
$matches = preg_split(
'#\[([a-zA-Z0-9\._]+)\]#',
$content,
...
-1
votes
1
answer
577
views
php first word only from mb string
I used preg_match but its returning pdf as it English that's why may be.
But I want to get only 練馬春日町Ⅳ
Is there any way to detect it for mb string.
<?php
// Initialize a sentence to a variable
...
0
votes
2
answers
447
views
PHP split string into integer, string and special character
I need to split this format of strings CF12:10 into array like below,
[0] => CF, [1] => 12, [2] => 10
Numbers and String of the provided string can be any length. I have found the php ...
-1
votes
3
answers
509
views
Split an alphanumeric string after each sequence of numbers
I have a series of strings in the form of
10a99b5c
55
2a3b1
g
How can I split the string by the characters (which always appears as a single character between numbers or in the beginning/end of the ...
2
votes
1
answer
114
views
Is there any option to separate special characters from words with regex/preg_split?
I'm junior and not at ease with regex, and I'm trying to do a password generator with sentences using regex and preg_split.
All is done except one thing, for example the sentence "I've got 2 cats." ...
-1
votes
1
answer
99
views
Preg_split regular expression how to split a string? [closed]
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] =&...
-2
votes
1
answer
107
views
Split/Explode a string in PHP
I need to split or explode a string.
K1123-Food, Apple, Z3456-Egg, Mushroom, M9902-Plant, Soil, Water, Q8876-Medicine, Car, Splitter
into something like
K1123-Food, Apple
Z3456-Egg, Mushroom
M9902-...
1
vote
3
answers
136
views
How can I split a string into an array?
I try to split my string into an array. All strings between the calculation signs +/*-:
$keywords = preg_split("/[\s,-]*[+-*]+/", "quanity*price/2+tax");
This is what I try to achieve:
Array
(
[...
0
votes
2
answers
109
views
preg_split() producing a single row array instead of splitting based on regex
Someone may spot this immediately, but I've been going blind on this search pattern and not sure what I'm missing.
// test string
$stringToSplit = "I awoke in the dim light of the fire pit surrounded ...