473,513 Members | 2,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php and regex (why no =~ like perl)?

Is there a good article that explains why php does not support =~ like
perl for regex? I am confused by all the different ways one can do
regex in php but it would seem supporting =~ would eliminate alot of
redundancy. What am i missing here?

Jul 17 '05 #1
7 1532
On Sun, 03 Jul 2005 21:08:30 -0700, el_roachmeister wrote:
Is there a good article that explains why php does not support =~ like
perl for regex? I am confused by all the different ways one can do
regex in php but it would seem supporting =~ would eliminate alot of
redundancy. What am i missing here?


PHP is not Perl. PHP5 has completely different object model, you have the
same kind of syntax for numeric and hash arrays and you have several types
of regex functions which can be categorized into preg functions and the
useless ones. Every other language except Perl (Python, Java, PL/SQL, PHP)
uses functions for regular expressions. Of course, if you've ever read Lex
and Yacc book, you know that =~ is also a function, only disguised as an
operator. Functional syntax is not much harder then the Perl one.

--
http://www.mgogala.com

Jul 17 '05 #2
The problem is the functional syntax i.e preg_match takes up alot more
space than a simple =~ . I write web-based software and my code is full
of regexs so the =~ saves a lot of space.

Also there seems to be several functions to do regex in php. I am not
sure which will even be supported in future releases?

Jul 17 '05 #3
el*************@yahoo.com wrote:
The problem is the functional syntax i.e preg_match takes up alot more
space than a simple =~ . I write web-based software and my code is full
of regexs so the =~ saves a lot of space.
If you really value typing as less as possible you should create your
own precompiler (or get a decent editor that does this stuff for you).
Also there seems to be several functions to do regex in php. I am not
sure which will even be supported in future releases?


Don't rely on PHP, there will be a newer and better language in the near
future.

Jul 17 '05 #4
On 4 Jul 2005 09:33:56 -0700, el*************@yahoo.com wrote:
Also there seems to be several functions to do regex in php. I am not
sure which will even be supported in future releases?


There's two main sorts. The POSIX-compatible ones, e.g. ereg. These come with
a warning to use the other sort, the Perl-compatible ones (PCRE), preg_replace
etc. What makes you think either will be removed in a future release anyway?

(BTW, use the PCRE ones).

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5
On Mon, 04 Jul 2005 09:33:56 -0700, el_roachmeister wrote:
The problem is the functional syntax i.e preg_match takes up alot more
space than a simple =~ . I write web-based software and my code is full
of regexs so the =~ saves a lot of space.
Yes, the space argument stands. Most of the modern editors, however,
are not limited by the line size of 80 characters, so you can create
nice looking programs that will take a little more space.
On the other hand, Perl grammar is very complex and full of idioms
which are unintelligible to the non-consecrated humans. One
such example is this:

$a ||= 'Value';

Translated into PHP, the above expression would be written like this:

if (!defined($a)) { $a='Value'; }

I agree that Perl version is much shorter but is also much less
readable and harder to master. It means that it takes much longer
to learn the language. Also, variables like $_,@_,$! and $~ are much
harder to learn. They're also crucial and you cannot use the language
if you don't know what this means:

while (<>) {
chomp;
print "Line:$_\n" if /^\d+\s{2,}/;
}

All of that makes Perl much harder to learn then PHP. The philosophy of
PHP is similar to the philosophy of the C language: let's make the
language as simple as possible so that people can learn it quickly.
That is why PHP became so popular. The object model of PHP is much
more natural and much easier then the Perl equivalent. Have you ever
tried @ISA array?

Also there seems to be several functions to do regex in php. I am not
sure which will even be supported in future releases?


PCRE library is supported by almost anything. I have no reason to believe
that they will go away in near future.

--
http://www.mgogala.com

Jul 17 '05 #6
I don't see how the object model prevents a shorter regexp syntax from
being implemented. Regexp could simply be treated as a different type.
You would something like:

$re = /\d+/;
if("12345" == $re) {
...
}

If they ever decide to integrate regexp in such a way I certainly would
not object. I wouldn't have a problem with a more compact way of
initializing arrays either. Heck, while we're at it, I would like named
arguments too.

Jul 17 '05 #7
El lunes 4, el roachmeister dijo:
Is there a good article that explains why php does not support =~ like
perl for regex? I am confused by all the different ways one can do
regex in php but it would seem supporting =~ would eliminate alot of
redundancy. What am i missing here?


Have a look at <http://tnx.nl/php#args>, it may be of help.

Cheers && good luck,

--
Cristian Gutierrez /* cr******@dcc.uchile.cl */
I didn't write this: A very complex macro did.
Jul 17 '05 #8

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

Similar topics

1
761
by: rdimayuga | last post by:
I need a regex pattern that will match a string starting with zero or one dot's. For example, ".string" and "string" should both match, but something like "estring" should not match. So far, I've tried the following: \.*string {0,1}string {0,1}string {0,1}string
2
4402
by: Sriram | last post by:
Hi, I am having trouble matching a regex that combines a negated character class and an anchor ($). Basically, I want to match all strings that don't end in a digit. So I tried: bash-2.05a@bermuda:15$perl -e 'while (<STDIN>) { if (/$/) { print;}}' skdsklds skdsklds
17
3942
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher http://forta.com/books/0672325667/
15
3213
by: Kay Schluehr | last post by:
I have a list of strings ls = and want to create a regular expression sx from it, such that sx.match(s) yields a SRE_Match object when s starts with an s_i for one i in . There might be relations between those strings: s_k.startswith(s_1) -> True or s_k.endswith(s_1) -> True. An extreme case would be ls = . For this reason SRE_Match should...
11
3072
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend a hand? import regsub
8
2226
by: Xah Lee | last post by:
the Python regex documentation is available at: http://xahlee.org/perl-python/python_re-write/lib/module-re.html Note that, i've just made the terms of use clear. Also, can anyone answer what is the precise terms of license of the official python documentation? The official python.org doc site is not clear. Note also, that the regex...
13
4496
by: brad | last post by:
Still learning C++. I'm writing some regex using boost. It works great. Only thing is... this code seems slow to me compared to equivelent Perl and Python. I'm sure I'm doing something incorrect. Any tips? #include <boost/regex.hpp> #include <iostream> // g++ numbers.cpp -o numbers -I/usr/local/include/boost-1_35...
0
828
by: MRAB | last post by:
I'm working on the sources for the regex module (_sre.c) but I've come across some behaviour that I wasn't aware of before: ('b', 'a') The regex module was modified to return this instead of the previous ('b', '') in issue #725106 because both Perl and sed returned this. My version of the module returns ('b', None), which was what I...
3
177
by: Jeff | last post by:
I'm parsing this: name="value" and sometimes it looks like this: name2="value2 without the closing '"'. I don't want to capture the end quote.
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7394
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7123
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5100
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.