473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

regular expression question: any character except a white space?

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 .* \?\>
Jul 17 '05 #1
12 14653
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.
Jul 17 '05 #2
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
Jul 17 '05 #3
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.
Jul 17 '05 #4
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
Jul 17 '05 #5
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
Jul 17 '05 #6
>>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)
Jul 17 '05 #7
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
Jul 17 '05 #8
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.
Jul 17 '05 #9
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.
Jul 17 '05 #10
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).

Jul 17 '05 #11
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
Jul 17 '05 #12
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...
Jul 17 '05 #13

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

Similar topics

4
by: peterbe | last post by:
I want to match a word against a string such that 'peter' is found in "peter bengtsson" or " hey peter," or but in "thepeter bengtsson" or "hey peterbe," because the word has to stand on its own....
0
by: brian fischer via .NET 247 | last post by:
Hello, I am trying to use a regular expression in Visual Basic Script tomatch some filenames within a folder. However, I am having someissues with the negative range character. I cannot seem to...
6
by: dreamerbin | last post by:
Hi, I'm having trouble extracting substrings using regular expression. Here is my problem: Want to find the substring that is immediately before a given substring. For example: from "00...
2
by: Jim Heavey | last post by:
Hello, I have an file that I am reading and it has some goffy characters in it and I want to use a regular expression to clean up those characters. I am not sure how to construct a regular...
6
by: alexrussell101 | last post by:
For anyone who can't be bothered to read my code and examples, scroll to the bottom, the question's there. Thanks. I'm using php and regular expressions to convert bbcode style things to html....
17
by: Randy Webb | last post by:
I know that the /g flag will match all occurrences. Is there a way, with a Regular Expression, to match all occurrences *except* the last one? pattern = /df/g; var myString = "asdfasdfasdfasdf";...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
2
by: Gunady | last post by:
Anybody know how is the Regular Expression pattern to find text that begin with , like string: ================================================================= Event Description: Some...
12
by: stevebread | last post by:
Hi, I am having some difficulty trying to create a regular expression. Consider: <tag1 name="john"/ <br/<tag2 value="adj__tall__"/> <tag1 name="joe"/> <tag1 name="jack"/> <tag2...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.