FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » glob patterns
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
glob patterns [message #183294] Sun, 20 October 2013 00:58 Go to next message
j is currently offline  j
Messages: 9
Registered: July 2011
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
I don't understand when to use {},[] or () in php glob matching

I want to match one or more numbers, either an a,w or h, a dash and then
a string.

120a-some_string or 1400w-some_string or 7h-some_string...

Is it:

glob('+{0-9}@{a,h,w}-some_string,GLOB_BRACE);

or is it?:

glob('+[0-9]@[ahw]-some_string');

or something else?

Jeff
Re: glob patterns [message #183303 is a reply to message #183294] Sun, 20 October 2013 08:50 Go to previous message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 20-10-2013 06:58, j wrote:
> I don't understand when to use {},[] or () in php glob matching
>
> I want to match one or more numbers, either an a,w or h, a dash and then
> a string.
>
> 120a-some_string or 1400w-some_string or 7h-some_string...
>
> Is it:
>
> glob('+{0-9}@{a,h,w}-some_string,GLOB_BRACE);
>
> or is it?:
>
> glob('+[0-9]@[ahw]-some_string');
>
> or something else?
>
> Jeff
>
>

> ls -l *some_string
-rw-r--r-- 1 luuk users 0 Oct 20 14:45 120a-some_string
-rw-r--r-- 1 luuk users 0 Oct 20 14:45 1400w-some_string
-rw-r--r-- 1 luuk users 0 Oct 20 14:45 7h-some_string
> php -r " print_r(glob('+[0-9]@[ahw]-some_string')); "
Array
(
)
> php -r " print_r(glob('+{0-9}@{a,h,w}-some_string',GLOB_BRACE)); "
Array
(
)
> php -r " print_r(glob('*-some_string')); "
Array
(
[0] => 120a-some_string
[1] => 1400w-some_string
[2] => 7h-some_string
)
>


i would go for:
> php -r " print_r(glob('[0-9]*[awh]-some_string')); "
Array
(
[0] => 120a-some_string
[1] => 1400w-some_string
[2] => 7h-some_string
)
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: alternative to fwrite?
Next Topic: Load Data from XML url
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Oct 17 15:00:00 EDT 2017

Total time taken to generate the page: 0.00532 seconds