I'm bad at regular expressions. Is this how I would look for any set
of characters that go more than 60 characters without a white space?
..{60}[^ ]
Also, does this match a block of PHP in an HTML page:
\<\?PHP .* \?\> 12 14498
lawrence wrote: I'm bad at regular expressions. Is this how I would look for any set of characters that go more than 60 characters without a white space?
.{60}[^ ]
No, almost ;-)
take this:
[^ ]{60,}
Also, does this match a block of PHP in an HTML page:
If there's no white space between, yes.
Are you looking for wordwrap()?
--> www.php.net/wordwrap
Saludo
Paul.
In article <c1*************@ID-205474.news.uni-berlin.de>,
Paul Wellner Bou <pa**********@united-scripts.com> wrote: lawrence wrote: I'm bad at regular expressions. Is this how I would look for any set of characters that go more than 60 characters without a white space?
.{60}[^ ]
No, almost ;-) take this:
[^ ]{60,}
That would catch 60 character strings, including those containing
whitespace characters such as newlines, tabs etc. Using preg_match or
preg_match_all:
/\S{61,}/
--
CC
CC Zona wrote: [^ ]{60,} That would catch 60 character strings, including those containing whitespace characters...
Excepting the white space character, and that was what he was asking
for. Ok, perhaps he wanted to include other white space characters,
too ;-)
such as newlines,...
Only using modifiers /sm.
tabs etc. Using preg_match or preg_match_all:
/\S{61,}/
Saludo
Paul.
In article <c1*************@ID-205474.news.uni-berlin.de>,
Paul Wellner Bou <pa**********@united-scripts.com> wrote: CC Zona wrote:[^ ]{60,} That would catch 60 character strings, including those containing whitespace characters...
Excepting the white space character, and that was what he was asking for.
In article <da**************************@posting.google.com >, lk******@geocities.com (lawrence) wrote:
I'm bad at regular expressions. Is this how I would look for any set of characters that go more than 60 characters without a white space?
"White space". Not "space character".
Ok, perhaps he wanted to include other white space characters, too ;-) such as newlines,...
Only using modifiers /sm.
Only if the poster chooses PCRE over ereg, which is unlikely for a regex
novice.
$alsowhitespace=array("\n","\r", "\t", "\v");
foreach ($alsowhitespace as $char)
{
$str="01234567890" . $char .
"1234567890123456789012345678901234567890123456789 ";
if (ereg("[^ ]{60,}",$str)) print "Wrong pattern";
}
--
CC
In article <cc**************************@netnews.comcast.net> ,
CC Zona <cc****@nospam.invalid> wrote: Ok, perhaps he wanted to include other white space characters, too ;-)
such as newlines,...
Only using modifiers /sm.
Only if the poster chooses PCRE over ereg, which is unlikely for a regex novice.
(And, only if either of the "s" or "m" modifier applied to the pattern in
question, which neither does. The class [^ ] matches newlines et al in
PCRE as well as ereg.)
--
CC
>>Only using modifiers /sm. Only if the poster chooses PCRE over ereg, which is unlikely for a regex novice.
Why that?
(I never worked with ereg... and at php.net they recommend using the
preg functions)
lawrence wrote: Also, does this match a block of PHP in an HTML page:
\<\?PHP .* \?\>
Did you try it? With no modifiers? All that matches is the string
"<?PHP" followed by a space followed by zero or more of any character
(except newlines, by default), followed by a space, followed by the
string "?>".
The answer to your question, then, is: possibly, depending on the
block's tags, its content and the rest of the file. It matches
almost none of the example blocks given in this newsgroup, for
example.
begin example
<script language=php>
$foo = '<?PHP '; $bar = ' ?>'
</script> http://www.php.net/manual/en/language.basic-syntax.php
--
Jock
Paul Wellner Bou <pa**********@united-scripts.com> wrote in message news:<c1*************@ID-205474.news.uni-berlin.de>... lawrence wrote: I'm bad at regular expressions. Is this how I would look for any set of characters that go more than 60 characters without a white space?
.{60}[^ ] No, almost ;-) take this:
[^ ]{60,}
Thanks much for the response. I've promised myself I'm going to master
regex this winter, but I've still a long way to go.
Are you looking for wordwrap()? --> www.php.net/wordwrap
As discussed in another thread I posted, I dislike wordwrap on the web
because in most situations I'm combining it with nl2br and it can lead
to jagged line edges. I don't remember why I couldn't put the wordwrap
after the nl2br, but for some reason I couldn't. ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) wrote in message news:<ab**************************@posting.google. com>... Try & learn with <http://www.weitz.de/regex-coach/>
Thanks. That was a great suggestion.
I've been using PHP for years now and I still can't do regexs.
Everytime I go to use them, it's like once in a blue moon, so I learn
just enough for that particular requirement, then all the knowledge
leaks out of my head again.
and then next time, it's back to square one.
I bought the oreiley book "mastering regular expressions" but I never
have the time to finish it -- and everytime I come back to it, I have to
start again :/
Everytime I try reading one of the many condensed guides, I go to use it
on my real-life problem and then something is missing. Something is
always missing. It's always a vital detail and I never know what it is
and I never know where to start looking to find the answer.
I don't know how many winters I promised myself I would sit down and
learn it properly. Now that I use XML/XSLT for 100% of my websites, I
have little need for crunching strings.
grrrrrrr
(well that post was completely useless wasn't it).
Terence wrote: I bought the oreiley book "mastering regular expressions" but I never have the time to finish it -- and everytime I come back to it, I have to start again :/
What do you think of what you've read so far?
(well that post was completely useless wasn't it).
I don't think so. But you're welcome to your opinion. :-)
--
Jock
John Dunlop wrote: Terence wrote:
I bought the oreiley book "mastering regular expressions" but I never have the time to finish it -- and everytime I come back to it, I have to start again :/
What do you think of what you've read so far?
I can't remember right now, it's been a few months since I started
reading it. I'll start reading it again and let you know... This discussion thread is closed Replies have been disabled for this discussion. Similar topics
4 posts
views
Thread by peterbe |
last post: by
|
reply
views
Thread by brian fischer via .NET 247 |
last post: by
|
6 posts
views
Thread by dreamerbin |
last post: by
|
2 posts
views
Thread by Jim Heavey |
last post: by
|
6 posts
views
Thread by alexrussell101 |
last post: by
|
17 posts
views
Thread by Randy Webb |
last post: by
|
6 posts
views
Thread by Ludwig |
last post: by
|
2 posts
views
Thread by Gunady |
last post: by
|
12 posts
views
Thread by stevebread |
last post: by
| | | | | | | | | | |