为什么我在RegExp中得到空结果?

the*_*row 1 php regex preg-match-all

我正在尝试使用此RegExp将我的URL解析为不同的部分:

([\w\\.-]*)
Run Code Online (Sandbox Code Playgroud)

给出一个示例URL http://www.foo.com/bar/baz我从preg_match_all()获得这些结果:

Array
(
[0] => Array
    (
        [0] => http
        [1] => 
        [2] => 
        [3] => 
        [4] => www.foo.com
        [5] => 
        [6] => bar
        [7] => 
        [8] => baz
        [9] => 
    )

)
Run Code Online (Sandbox Code Playgroud)

它似乎将任何无效字符解析为空项.
我该如何解决这个问题?

Gre*_*reg 6

通过使用*您捕获空组 - 请+改为使用:

([\w\.-]+)
Run Code Online (Sandbox Code Playgroud)

我假设您的RE中的额外\是因为您在引用的字符串中有它.