Regex match for split

Adam Hladík
fontSize=16.0, fontFamily=sans, align=0, color=FF0000, text="foo, bar"

and I need match for spit. Output will be

array(
  'fontSize'=>'16.0',
  'fontFamily'=>'sans',
  'align'=>'0',
  'color'=>'FF0000',
  'text'=>'foo, bar'
);

I tried next, but it was bad:

preg_spit("~[\s]="?[\s]"?,~", $string);
Avinash Raj

Just split your input string according to the below regex,

,\s(?![^=]*")

DEMO

<?php
$str = 'fontSize=16.0, fontFamily=sans, align=0, color=FF0000, text="foo, bar"';
$regex = '~,\s(?![^=]*")~';
$splits = preg_split($regex, $str);
print_r($splits);
?>

Output:

Array
(
    [0] => fontSize=16.0
    [1] => fontFamily=sans
    [2] => align=0
    [3] => color=FF0000
    [4] => text="foo, bar"
)

Regular Expression:

,                        ','
\s                       whitespace (\n, \r, \t, \f, and " ")
(?!                      look ahead to see if there is not:
  [^=]*                    any character except: '=' (0 or more
                           times)
  "                        '"'
)                        end of look-ahead

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Java split regex non-greedy match가 작동하지 않습니다.

분류에서Dev

Regex.Split on "()"및 "?"

분류에서Dev

Regex: How to split by "=" and not by "!="

분류에서Dev

regex (?!) and (?=) and null match

분류에서Dev

Regex multiline match

분류에서Dev

Match regex with \\n in it

분류에서Dev

Regex match tag with no spaces

분류에서Dev

Regex to match URL in Powershell

분류에서Dev

Regex to match end of the word

분류에서Dev

.match() problems with regex

분류에서Dev

add apostrophe to regex match

분류에서Dev

RegEx to match list

분류에서Dev

Regex match in jQuery

분류에서Dev

Regex match everything after conditional match

분류에서Dev

Regex Split String at particular word

분류에서Dev

Python Regex match: include Regex syntax

분류에서Dev

std :: regex_match with characters é è à

분류에서Dev

Regex to match partial string verification

분류에서Dev

RegEx: Match everything but X, then X

분류에서Dev

Append text to part of regex match

분류에서Dev

Regex match a string if its in the end

분류에서Dev

Recursively rename subdirectories that match a regex

분류에서Dev

Java regex match outside bracks

분류에서Dev

regex backtracking to value within match

분류에서Dev

Regex to match conditional IP address

분류에서Dev

Regex: Match Optional URI Parameters

분류에서Dev

Regex match for starting character or _\w

분류에서Dev

Regex - Match.end() is not correct

분류에서Dev

Regex to match domain without subfolder