我正在寻找在 php 中创建一个从以下格式获取数据的正则表达式:
"1,2,3;7,1,3;1" returns an $matches array with "(1,2,3,7,1,3,1)"
"1" returns an $matches with "(1)"
"1;1;3;5;7;10;999" returns an $matches array with "(1,1,3,5,7,10,999)"
"1,1,1;2,5;3,4" doesn't pass since numbers are repeating within semicolon boundaries
"2,3,4;5,;" doesn't pass since it doesn't satisfy the format.
(示例中的引号是为了使它们更易于阅读;它们不应出现在实际结果中。)
格式是用逗号或分号分隔的数字,在分号内它们不会相互重复。它不应该接受任何其他格式。
我试过/(^(\d{1,3})$)|(([0-9]+)([,|;]{1}[0-9]+)+)/
了,但没有用。我也试过/[0-9]+([,|;]{1}[0-9]+)+/
,但也没有用。当我得到 $matches 数组时,它没有我需要的值,如上所述。
我在PHP 5.2中这样做。谢谢。