dongyang9813
dongyang9813
2012-09-21 00:15

正则表达式匹配 - 无法解决

  • regex
  • pcre
  • php

I've got a string that I need to parse into an array in PHP. The string looks something like this:

(Key: ALL_HTTP)(Value:HTTP_HOST:10.1.1.1 )(Key: ALL_RAW)(Value:Host: 10.1.1.1:80 )(Key: APPL_MD_PATH)(Value:/ROOT)(Key: AUTH_TYPE)(Value:)(Key: AUTH_USER)(Value:)(Key: AUTH_PASSWORD)(Value:)(Key: LOGON_USER)(Value:)(Key: REMOTE_USER)(Value:)

The number of "key/value" pairs could be unlimited but is usually about 30-40 per string.

I've been playing with preg_match and a variation of an example from PHP.net - something like this:

preg_match('/(\S+): (\S+)/', $string, $result);

That gets me back the first key as $result[0] but doesn't help for the rest.

If anyone could help me with a proper expression that would be fantastic. I'd also appreciate any good reading resources for splitting strings with PCRE.

Thanks all!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换