PHP Developers Network
http://forums.devnetwork.net/

Help in Regular Expression
http://forums.devnetwork.net/viewtopic.php?f=38&t=141302
Page 1 of 1

Author:  RuchiSaini [ Sat May 16, 2015 3:53 am ]
Post subject:  Help in Regular Expression

Hi,

Can you please advice me on following regular expressions

1)(green|blue)?+.+
i understood that it will take either green or blue which is optional but +.+
changes its meaning and it accepts colors which are not green and blue
but i dont understand how is it affecting

2)^([\"']?)\\d\\d:\\d\\d\\1,([\"']?)[A-Z]\\w+\\2,.*$"
It accepts
10:23,Added,Queue,7432e01
10:53,"Removed","Queue","7432e01"
10:23,Added,,queue 2,7432e01
i believe backreferences are used here then they shd be using
value in capturing group only , why are these two value accepted -> Added,Queue.
Also if you check the third line, if i dont give any value then that is also accepted
Please guide

Thanks
Ruchi

Author:  requinix [ Sat May 16, 2015 6:24 am ]
Post subject:  Re: Help in Regular Expression


Author:  RuchiSaini [ Sat May 16, 2015 7:59 am ]
Post subject:  Re: Help in Regular Expression

2) I got it ...thanks :)

1) For RegEx (green|blue)?+.+
and String value : green
Match fails
and String value : red
Match passes
So actually I didnt get your answer or maybe i have not posted my question properly

Thank you so much
Ruchi

Author:  requinix [ Sat May 16, 2015 8:03 am ]
Post subject:  Re: Help in Regular Expression

Two parts
1. (green|blue)?+
2. .+

"green" matches the first part but since there isn't anything after it does not match the second part. Because of the ?+ the engine will not backtrack to undo the first match (which was optional) so that it can make the second instead. If you change it to just ? then it would backtrack and the string would match.
"red" does not match the optional first part but does match the second part.

Author:  RuchiSaini [ Sat May 16, 2015 9:36 am ]
Post subject:  Re: Help in Regular Expression

okay got it...thank u so much :)

Author:  RuchiSaini [ Sun May 17, 2015 7:03 am ]
Post subject:  Re: Help in Regular Expression

Hi,

You have said that backtracking plays a significant role in how regexes are generally used.

I am not aware of these guidelines...can u guide me any link/site which is a good reference point to understand that

Thanks

Author:  requinix [ Sun May 17, 2015 7:20 am ]
Post subject:  Re: Help in Regular Expression

Not really - backtracking is one of those things most people rely upon without realizing it. Which is why things like possessive quantifiers (?+, *+, ++) or their nicer relative once-only subpatterns (?>...) can easily break someone's regex.

If you want to learn, is a good place to start. The documentation for Perl's perlre is another place to get more technical information, and of course there's PHP's own PCRE documentation.

Author:  RuchiSaini [ Sun May 17, 2015 7:48 am ]
Post subject:  Re: Help in Regular Expression

okay...will go thru these sites...thanks

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/