1

我希望America/Chicago从这个字符串中得到

Local Time Zone (America/Chicago (CDT) offset -18000 (Daylight))

并让它适用于其他时区,例如America/Los_AngelesAmerica/New_York等等。我不是很好,prey_match_all而且,如果有人可以指导我学习如何正确学习它的好教程,因为这是我第三次需要使用它。

4

2 回答 2

2

这是您使用我的正则表达式的解决方案

代码

    $in = "Local Time Zone (America/Chicago (CDT) offset -18000 (Daylight))";
    preg_match_all('/\(([A-Za-z0-9_\W]+?)\\s/', $in, $out);
    echo "<pre>";
    print_r($out[1][0]);

 ?>

和输出

America/Chicago

希望这对你有帮助。

于 2013-08-21T04:58:09.807 回答
0

我会使用正则表达式:\((\S+)

preg_match_all('/\((\S+)/', $in, $out);

解释:

The regular expression:

(?-imsx:\((\S+))

matches as follows:

NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  \(                       '('
----------------------------------------------------------------------
  (                        group and capture to \1:
----------------------------------------------------------------------
    \S+                      non-whitespace (all but \n, \r, \t, \f,
                             and " ") (1 or more times (matching the
                             most amount possible))
----------------------------------------------------------------------
  )                        end of \1
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------
于 2013-08-21T17:22:11.190 回答