473,408 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Order of expression in preg_split

Hello:

Using PHP 4.3.11

The line: $strDate = preg_split('/[\.\/-]/', $my_date);
works to break apart a date in the form mm/dd/yyyy or mm.dd.yyyy or
mm-dd-yyyy
but the line: $strDate = preg_split('/[\/-\.]/', $my_date);
doesn't work.

Why does the order of the items make a difference?

Thanks,

Ken
Feb 16 '06 #1
3 2351
d
"none" <""krwl\"@(none)"> wrote in message
news:ML********************@rcn.net...
Hello:

Using PHP 4.3.11

The line: $strDate = preg_split('/[\.\/-]/', $my_date);
works to break apart a date in the form mm/dd/yyyy or mm.dd.yyyy or
mm-dd-yyyy
but the line: $strDate = preg_split('/[\/-\.]/', $my_date);
doesn't work.

Why does the order of the items make a difference?
In a regular expression character class definition (the bit in the []s), a
hyphen denotes a range of characters, so [a-z] will match all lowercase
letters of the alphabet, and [0-9] will match all numbers from 0 to 9. If
you escape your hyphen, it doesn't matter where you put it in your class.

$strDate = preg_split('/[\/\-\.]/', $my_date);
Thanks,

Ken


hope that helps!

dave
Feb 16 '06 #2
"d" <d@example.com> wrote:
In a regular expression character class definition (the bit in the []s), a
hyphen denotes a range of characters, so [a-z] will match all lowercase
letters of the alphabet, and [0-9] will match all numbers from 0 to 9. If
you escape your hyphen, it doesn't matter where you put it in your class.

$strDate = preg_split('/[\/\-\.]/', $my_date);


Absolutely right. Also, this is rather trivial, but you shouldn't need to
escape the . in a character class, it's only a token when used outside a
character class. When inside a character class, the dot as well as
quantifiers (like *, ? etc.) are interpreted as literals.

Allen
Feb 16 '06 #3
Al13n wrote:
In a regular expression character class definition (the bit in the []s), a
hyphen denotes a range of characters, so [a-z] will match all lowercase
letters of the alphabet, and [0-9] will match all numbers from 0 to 9. If
you escape your hyphen, it doesn't matter where you put it in your class.

$strDate = preg_split('/[\/\-\.]/', $my_date);

Absolutely right. Also, this is rather trivial, but you shouldn't need to
escape the . in a character class, it's only a token when used outside a
character class. When inside a character class, the dot as well as
quantifiers (like *, ? etc.) are interpreted as literals.


Allen and Dave:

Thanks very much for your help. I'm surprised that /[\.\/-]/ worked at
all! A better way to have written it would have been: #[./\-]# which
works great.

Thanks, again.

Ken
Feb 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Peter | last post by:
L.S. I am trying to cut a string into substrings. The string at hand looks something like this: $data='one|two|three|four\nfive|six|seven|eight'; //observe the chr(10) in the middle I...
16
by: Sims | last post by:
Hi, I need some help to split data using regular expression Consider the string '1,2,3', I can split it using, preg_split("/,/", '1,2,3') and i correctly get =1, =2,=3. Now if i have
15
by: voipcanada | last post by:
is there any thing we can write to keep the right txt to the = sign in the preg_split. from the following lines DST-NUMBER-IN=0033512877596, DST-NUMBER-OUT=98751#33512877596,...
8
by: der | last post by:
Hello all, I've a question about order of evaluations in expressions that have && and || operators in them. The question is: will the evalution go left-to-right, no matter what -- even if the...
16
by: mdh | last post by:
May I ask the group the following: (Again, alas , from K&R) This is part of a function: while ( ( array1 = array2 ) != '\0' ); /* etc etc */ Is this the order that this is evaluated? ...
5
by: chadsmith76 | last post by:
hello, I have listings with coordinates, i would like to do ORDER BY and display listings with coords first. If they don't have coords the value is blank and the coords go both positive and...
0
by: tiggman | last post by:
Why preg_split works only if the char # before the delimiter is 21 or less? example php code: ============= $right = "{Hello Im very aaaaaa {cool|not cool}}"; print $right."<br>"; $pattern =...
15
by: Jeroen | last post by:
Hi all, I've got a very specific question about the evaluation order in C++. Assume some kind of custom array class, with an overloaded subscript operator. In the following code: { my_array...
3
by: mark1491 | last post by:
I am trying to split a string into sentences with preg_split, but I would like it to not split initials. Examples: Mark H. Doolittle is my name. What is yours. ( I don't want it to split the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.