473,373 Members | 1,135 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,373 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 14666
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: 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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.