Latest revision |
Your text |
Line 21: |
Line 21: |
| I think that if you do want all the matches in perl, you are better off doing it in an explicit loop, so as to avoid creating an unneeded array. | | I think that if you do want all the matches in perl, you are better off doing it in an explicit loop, so as to avoid creating an unneeded array. |
| (Perl now considers using the "complete match" token to be a less than ideal thing to use, which is why I added the parens and used <code>$1</code> instead of <code>$&</code>.) --[[User:Divad27182|Divad27182]] ([[User talk:Divad27182|talk]]) 06:33, 9 February 2013 (UTC) | | (Perl now considers using the "complete match" token to be a less than ideal thing to use, which is why I added the parens and used <code>$1</code> instead of <code>$&</code>.) --[[User:Divad27182|Divad27182]] ([[User talk:Divad27182|talk]]) 06:33, 9 February 2013 (UTC) |
− |
| |
− | :<code>($firstMatch) = $str =~ /([a-z])/i</code> [[Special:Contributions/199.27.128.24|199.27.128.24]] 05:36, 13 January 2014 (UTC)
| |
− |
| |
− | If you're havin' Perl problems I feel bad for you, son - I got 99 problems, but regex ain't one. {{unsigned|150.252.114.126}}
| |
− |
| |
− | [User talk:Divad27182] is right. I took the liberty to remove the Perl reference in that line. [[Special:Contributions/87.165.125.229|87.165.125.229]] 10:05, 11 February 2013 (UTC)
| |
− |
| |
− | [[Special:Contributions/192.193.116.137|192.193.116.137]] 15:47, 11 February 2013 (UTC)Is there not an "off by one" joke in here also?
| |
− |
| |
− | ::"I don't understand why so many people have problems with regular expressions." I think there are a few reasons
| |
− | ::1: the syntax crams everything together giving the coder little scope for laying things out. As the number of levels of nesting increases this makes it very hard to see the tree structure.
| |
− | ::2: the way syntax characters are mixed with literal characters without clear delimination makes it very difficult for those who are not intimately famility with the format to quickly distinguish which is syntax and what is literal text to be matched (see shell script for an example of a programming language that has the same problem) or to curse when they don't realise a paticular character is used as syntax.
| |
− | ::3: there is little in the way of debugging support when a regex doesn't match the way you expect it to.
| |
− | ::4: there are some really nasty corner cases of regexes that are simple to write but massively hard for the regex engine to check [http://www.regular-expressions.info/catastrophic.html]. -- [[w:user:plugwash]] {{unsigned ip|141.101.98.248}}
| |
− |
| |
− |
| |
− | Very late to the party but I wanted to reply to [[w:user:plugwash]] and say that Perl has at least made an improvement on your point 1. "the syntax crams everything together giving the coder little scope for laying things out". One can use the x flag, which allows arbitrary amounts of whitespace in the regex:
| |
− |
| |
− | <code>
| |
− | $str = 'foobar';
| |
− | $result = $str =~ m/
| |
− | foo
| |
− | (
| |
− | [b|c]
| |
− | )
| |
− | [^z]
| |
− | r
| |
− | /x;
| |
− | print "Result: $result\n";
| |
− | print "Captured: $1\n";
| |
− | </code>
| |
− | With of course the remaining problem being if you ''want'' whitespace, you have to explicitly add it back in. [[User:AmbroseChapel|AmbroseChapel]] ([[User talk:AmbroseChapel|talk]]) 06:24, 31 August 2017 (UTC)
| |
− |
| |
− | If I can take a second to point this out for you youngsters, the "I got 99 problems but a bitch ain't one" line came from Ice T originally (from "99 Problems" on the "Home Invasion" album: hardly his best work. [[Special:Contributions/141.101.107.84|141.101.107.84]] 15:16, 20 September 2017 (UTC)Endie
| |