473,394 Members | 1,722 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,394 software developers and data experts.

Regural expression strange behaviour

I have the following code (I need to extract everything between
slash):

$buff="0,x,R / 1,y,R / - / 1,y,R";

preg_match_all("/\s*([0-9]\s*,\s*[a-z]\s*,\s*.\s*)\s*[\/]\s*|\s*(-)\s*[\/]/U",$buff,$izlaz);

var_dump($izlaz);
This outputs:

array(3) {
[0]=>
array(4) {
[0]=>
string(7) "0,x,R /"
[1]=>
string(8) " 1,y,R /"
[2]=>
string(4) " - /"
[3]=>
string(8) " 1,y,R"
}

[1]=>
array(4) {
[0]=>
string(5) "0,x,R"
[1]=>
string(5) "1,y,R"
[2]=>
string(0) ""
[3]=>
string(5) "1,y,R"
}

[2]=>
array(4) {
[0]=>
string(0) ""
[1]=>
string(0) ""
[2]=>
string(1) "-"
[3]=>
string(0) ""
}
}

Problem is in the 3rd row: why is it there? I would expect '-' sign in
2nd row...
Jul 17 '05 #1
2 1399
On Tue, 18 Jan 2005 22:20:09 +0100, Josip <nj*****@gmail.com> wrote:
I have the following code (I need to extract everything between
slash):

$buff="0,x,R / 1,y,R / - / 1,y,R";

preg_match_all("/\s*([0-9]\s*,\s*[a-z]\s*,\s*.\s*)\s*[\/]\s*|\s*(-)\s*[\/]/U",$buff,$izlaz);


Hm, this is partial solution...

preg_match_all("/(\s*[0-9]\s*,\s*[a-z]\s*,\s*[LR]\s*\s*|\s*[\-]\s*)[\/]\s*/U",$buff,$izlaz);

Jul 17 '05 #2
Josip wrote:
I have the following code (I need to extract everything between
slash):

$buff="0,x,R / 1,y,R / - / 1,y,R";

preg_match_all("/\s*([0-9]\s*,\s*[a-z]\s*,\s*.\s*)\s*[\/]\s*|\s*(-)\s*[\/]/U",$buff,$izlaz);
Is that really your pattern? I only ask because the output
below doesn't come from that.
var_dump($izlaz);
This outputs:

array(3) {
[0]=>
array(4) {
No it doesn't. There are only three matches to the full
pattern in your subject string.
[0]=>
string(7) "0,x,R /"
[1]=>
string(8) " 1,y,R /"
[2]=>
string(4) " - /"
[3]=>
string(8) " 1,y,R"
The last string here doesn't match because there must be a
slash at the end. You should allow the last slash to be
optional in your pattern. Consider:

`(\d\s*,\s*[a-z]\s*,\s*.|-)\s*/?`

[ ... ]
Problem is in the 3rd row: why is it there? I would expect '-' sign in
2nd row...


Your subject string is '0,x,R / 1,y,R / - / 1,y,R'. The
hyphen is in the third segment, not the second. Move the
hyphen to the second segment and watch what happens.

--
Jock
Jul 17 '05 #3

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

Similar topics

0
by: Frank Passek | last post by:
Dear all, I've encountered some strange behaviour with PHP (4.3.2) using the CLI-API. When I provide an option in the first line of my script like so: #!/usr/bin/php -c /path_to_my_ini_file and...
2
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from...
3
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ...
3
by: Sebastian C. | last post by:
Hello everybody Since I upgraded my Office XP Professional to SP3 I got strange behaviour. Pieces of code which works for 3 years now are suddenly stop to work properly. I have Office XP...
6
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd...
31
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
17
by: matevzb | last post by:
I've ran into some fishy code that, at first glance, is buggy, but it seems to work correctly and none of the compilers I've tried (five so far, on various systems) gives any warnings. The code:...
4
by: Gotch | last post by:
Hi, I'm getting a very strange behaviour while running a project I've done.... Let's expose it: I've two projects. Both of them use a Form to do some Gui stuff. Other threads pack up messages...
8
by: Daniel Kraft | last post by:
Hi, I did encounter a strange problem in my C program, and traced it down; it looks like I get different results for bit left shifts when the bit count is a constant or a funtion-return value. ...
8
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.