preg-split

PHP Regex to match the last occurrence of a string

时光总嘲笑我的痴心妄想 提交于 2020-01-13 13:11:06
问题 My string is $text1 = 'A373R12345' I want to find last none digital number occurrence of this string. So I use this regular expression ^(.*)[^0-9]([^-]*) Then I got this result: 1.A373 2.12345 But my expected result is: 1.A373R (It has 'R') 2.12345 Another example is $text1 = 'A373R+12345' Then I got this result: 1.A373R 2.12345 But my expected result is: 1.A373R+ (It has '+') 2.12345 I want contain the last none digital number!! Please help !! thanks!! 回答1: $text1 = 'A373R12345'; preg_match(

PHP preg_split on spaces, but not within tags

倖福魔咒の 提交于 2020-01-06 19:53:24
问题 i am using preg_split("/\"[^\"]*\"(*SKIP)(*F)|\x20/", $input_line); and run it on phpliveregex.com it produce array : array(10 0=><b>test</b> 1=>or 2=><em>oh 3=>yeah</em> 4=>and 5=><i> 6=>oh 7=>yeah 8=></i> 9=>"ye we 'hold' it" ) NOT what i want, it should be seperate by spaces only outside html tags like this: array(5 0=><b>test</b> 1=>or 2=><em>oh yeah</em> 3=>and 4=><i>oh yeah</i> 5=>"ye we 'hold' it" ) in this regex i am only can add exception in "double quote" but realy need help to add

How can I ignore “XXX” titles in my data parsing script?

依然范特西╮ 提交于 2020-01-06 08:14:11
问题 I've tried and it doesn't seem to work. Any help would be greatly appreciated. CODE: foreach (glob('mov/Alene*.mov') as $filename){ $theData = file_get_contents($filename) or die("Unable to retrieve file data"); } $string = $theData; $titles = explode("\n", $string); function getInfo($string){ $Ratings = ['G', 'PG', 'PG-13', 'R', 'NR', 'XXX']; $split = preg_split("/\"(.+)\"/", $string, 0, PREG_SPLIT_DELIM_CAPTURE); if(count($split) == 3){ preg_match("/(".implode("|", $Ratings).")\s/", $split

string to array, split by single and double quotes

半世苍凉 提交于 2019-12-31 01:39:25
问题 i'm trying to use php to split a string into array components using either " or ' as the delimiter. i just want to split by the outermost string. here are four examples and the desired result for each: $pattern = "?????"; $str = "the cat 'sat on' the mat"; $res = preg_split($pattern, $str); print_r($res); /*output: Array ( [0] => the cat [1] => 'sat on' [2] => the mat )*/ $str = "the cat \"sat on\" the mat"; $res = preg_split($pattern, $str); print_r($res); /*output: Array ( [0] => the cat [1

Regex to match comma not between grouping symbols

谁都会走 提交于 2019-12-30 06:50:15
问题 I need a regular expression that will match a comma that is NOT between either a '[' and ']' or '(' and ')' or '{' and '}'. Other grouping symbols do not matter. I have tried to figure it out but I cannot come up with anything that accomplishes this. The regex is to be used with the PHP preg_split function to split a string on the matched commas. An example string containing commas and grouping symbols: <div>Hello<div>,@func[opt1,opt2],{,test},blahblah The string should split up as follows: 1

Regex to match comma not between grouping symbols

对着背影说爱祢 提交于 2019-12-30 06:48:50
问题 I need a regular expression that will match a comma that is NOT between either a '[' and ']' or '(' and ')' or '{' and '}'. Other grouping symbols do not matter. I have tried to figure it out but I cannot come up with anything that accomplishes this. The regex is to be used with the PHP preg_split function to split a string on the matched commas. An example string containing commas and grouping symbols: <div>Hello<div>,@func[opt1,opt2],{,test},blahblah The string should split up as follows: 1

How do I include the split delimiter in results for preg_split()?

試著忘記壹切 提交于 2019-12-28 00:20:39
问题 I have this simple pattern that splits a text into periods: $text = preg_split("/[\.:!\?]+/", $text); But I want to include . : or ! at the end of the array items. That is, now for "good:news.everyone!" I have: array("good", "news", "everyone", ""); But I want: array("good:", "news.", "everyone!", ""); 回答1: Here you go: preg_split('/([^.:!?]+[.:!?]+)/', 'good:news.everyone!', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); How it works: The pattern actually turns everything into a

How do I include the split delimiter in results for preg_split()?

落花浮王杯 提交于 2019-12-28 00:20:12
问题 I have this simple pattern that splits a text into periods: $text = preg_split("/[\.:!\?]+/", $text); But I want to include . : or ! at the end of the array items. That is, now for "good:news.everyone!" I have: array("good", "news", "everyone", ""); But I want: array("good:", "news.", "everyone!", ""); 回答1: Here you go: preg_split('/([^.:!?]+[.:!?]+)/', 'good:news.everyone!', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); How it works: The pattern actually turns everything into a

php: split string into 3 parts by two delimiters where the first and the last “delimiters” are letters or numbers respectively

旧时模样 提交于 2019-12-23 02:58:18
问题 Any ideas how to split string into 3 parts where by two "delimiters" where the first and the last "delimiters" are letters or numbers respectively? $str = "%@-H-e-l-l-o-7-9#$%"; would be split like this: $arr=("%@-","H-e-l-l-o-7-9", "#$%"); and $str = "Hi$73"; would be split like this: $arr=("","Hi$73", ""); and $str = "Беларусь!"; would be split like this: $arr=("","Беларусь", "!"); and $str = "!"; would be split like this: $arr=("!","", ""); and $str = ""; would be split like this: $arr=(""

PHP preg_split with two delimiters unless a delimiter is within quotes

﹥>﹥吖頭↗ 提交于 2019-12-22 10:57:41
问题 Further on from my previous question about preg_split which was answers super fast, thanks to nick; I would really like to extend the scenario to no split the string when a delimiter is within quotes. For example: If I have the string foo = bar AND bar=foo OR foobar="foo bar" , I'd wish to split the sting on every space or = character but include the = character in the returned array (which works great currently), but I don't want to split the string either of the delimiters are within quotes