正则表达式,(preg_split等......),请帮助一些。 [英] Regular expression, (preg_split etc...), some help please.
问题描述
我需要一些帮助才能使用正则表达式分割数据
考虑字符串
''1,2,3'',我可以使用,preg_split(" /,/",''1,2,3'')拆分它,我正确
得到[0] = 1,[1] = 2,[2] = 3.
现在如果我有
'' 1,2,3''我可以使用preg_split(" /(?<!\"),/ \d",''1," 2,3"'')拆分它并且我
正确得到[0] = 1,[1] =" 2,3"
但它显然不能用于更多高级案例,例如
''1," 2,3,或1,2,3,主要是因为/ d不再有用。
那么如何搜索常规表达式*不在*
撇号内?
我想我可能要写自己的分割功能,特别是如果我有一个
极端情况,例如''1," 2,\ 3'',(注意逃避撇号)。
非常感谢您的投入。
Sims
>
在文章< c0 ************* @ ID-162430.news.uni-berlin.de>中,
模拟人生 < SI ********* @ hotmail.com>写道:
考虑字符串
''1,2,3'',我可以使用它分割它,preg_split(" /,/" ,''1,2,3'')我正确地得到[0] = 1,[1] = 2,[2] = 3.
现在,如果我有
''1," 2,3"''我可以使用preg_split(" /(?<!\"),/ \d",''1来拆分它2,3和
正确得到[0] = 1,[1] =" 2,3"
但它显然不起作用更高级的案例,例如
''1," 2,3或1,2,3主要是因为/ d不再有用。
总体目标是什么提取具有任意分隔符的数字?如果是这样的话,
如何拆分/ \ D + /?
-
CC
在文章< c0 ************* @ ID-162430.news.uni-berlin.de>,
模拟人生 < SI ********* @ hotmail.com>写道:
考虑字符串
''1,2,3'',我可以使用它分割它,preg_split(" /,/" ,''1,2,3'')我正确地得到[0] = 1,[1] = 2,[2] = 3.
现在,如果我有
''1," 2,3"''我可以使用preg_split(" /(?<!\"),/ \d",''1来拆分它2,3和
正确得到[0] = 1,[1] =" 2,3"
但它显然不起作用更高级的案例,例如
''1," 2,3或1,2,3主要是因为/ d不再有用。
(哎呀,永远不会请注意上一篇文章。)
-
CC
2004年2月12日星期四08:49:59 +0200,Sims写道:我需要一些帮助来使用正则表达式分割数据
不,你不要'' t :) http://www.php.net/fgetcsv
Hi,
I need some help to split data using regular expression
Consider the string
''1,2,3'', I can split it using, preg_split("/,/", ''1,2,3'') and i correctly
get [0]=1, [1]=2,[2]=3.
Now if i have
''1,"2,3"'' i could split it using preg_split("/(?<!\"),/\d", ''1,"2,3"'') and i
correctly get [0]=1, [1]="2,3".
But it clearly does not work in some more advanced cases, for example
''1," 2 , 3"'' or ''1,"2 , 3 "'' mainly because the /d is no longer useful.
So how can i search for a regular expression that is *not within*
apostrophes?
I think i might have to write my own split function especially if i have an
extreme case like, ''1," 2 , \" 3"'', (note the escape apostrophe).
Many thanks for you input.
Sims
In article <c0*************@ID-162430.news.uni-berlin.de>,
"Sims" <si*********@hotmail.com> wrote:
Consider the string
''1,2,3'', I can split it using, preg_split("/,/", ''1,2,3'') and i correctly
get [0]=1, [1]=2,[2]=3.
Now if i have
''1,"2,3"'' i could split it using preg_split("/(?<!\"),/\d", ''1,"2,3"'') and i
correctly get [0]=1, [1]="2,3".
But it clearly does not work in some more advanced cases, for example
''1," 2 , 3"'' or ''1,"2 , 3 "'' mainly because the /d is no longer useful.
Is the overall goal to extract numbers having arbitrary separators? If so,
how about splitting on "/\D+/"?
--
CC
In article <c0*************@ID-162430.news.uni-berlin.de>,
"Sims" <si*********@hotmail.com> wrote:
Consider the string
''1,2,3'', I can split it using, preg_split("/,/", ''1,2,3'') and i correctly
get [0]=1, [1]=2,[2]=3.
Now if i have
''1,"2,3"'' i could split it using preg_split("/(?<!\"),/\d", ''1,"2,3"'') and i
correctly get [0]=1, [1]="2,3".
But it clearly does not work in some more advanced cases, for example
''1," 2 , 3"'' or ''1,"2 , 3 "'' mainly because the /d is no longer useful.
(Oops, never mind that last post. )
--
CC
On Thu, 12 Feb 2004 08:49:59 +0200, Sims wrote:I need some help to split data using regular expression
No you don''t :) http://www.php.net/fgetcsv
这篇关于正则表达式,(preg_split等......),请帮助一些。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!