Some general questions

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Some general questions

Post by WaldoMonster »

I have played around with RegexBuddy and PHP Regular Expression last days.
And have some unanswered questions.

Is there functional a difference between these two expressions?
Witch is preferred?

Code: Select all

^(leading|)(start.*)
^(leading)?(start.*)
I assume there is no difference between these PHP Regular Expression?
I found the last two better readable in combination with the / escape.

Code: Select all

'\(something.*)\'
'%(something.*)%'
'#(something.*)#'
So far I found these options in PHP:
s Dot matches new line
i Case insensitive
m ^$ match at line break
Are there more options?

Thanks,

Willem
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Re: Some general questions

Post by stereofrog »

WaldoMonster wrote: Is there functional a difference between these two expressions?
Witch is preferred?

Code: Select all

^(leading|)(start.*)
^(leading)?(start.*)
There's no logical difference, however ? is far more common.
I found the last two better readable in combination with the / escape.

Code: Select all

'\(something.*)\'
'%(something.*)%'
'#(something.*)#'
Another common delimiter is tilde (~), imo it's more readable than %.
# has its uses in regexp.
Are there more options?
Yes, see

http://www.php.net/manual/en/reference. ... ifiers.php
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

Thanks for the help.
Post Reply