470,849 Members | 1,123 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

RegExp pattern to scan for NO HTML tags - need help

I am having to use an existing FormValidator class to check form
elements, and one of the things I must check is to see if someone
entered tags in the string <>; if so, it must flag for that.

However, the catch is that, the way FormValidator class is written, I
can't use this pattern:

/<[^>]+>/

because it needs to check for the pattern of the NEGATION of that for
FormValidator class to work. In other words, it must match the pattern
something like this:

! /<[^>]+>/

But the only way I can do this is to create a pattern and nothing
more; no other code of any kind except the literal pattern formed in
such a way to check for everything BUT a tag!

I also cannot use str_replace and strip out the tags; I can't use
htmlentities and translate the tags.. the requirements are to FLAG the
user if a tag is found but by NOT using the pattern to find one, but
to ONLY use the pattern to find the NEGATION of finding one!!!

Mind bender, I know.

HELP!

Phil
Jul 17 '05 #1
7 6129
On 29 Jan 2004 11:21:23 -0800, so*****@erols.com (Phil Powell) wrote:
I am having to use an existing FormValidator class to check form
elements, and one of the things I must check is to see if someone
entered tags in the string <>; if so, it must flag for that.

However, the catch is that, the way FormValidator class is written, I
can't use this pattern:

/<[^>]+>/

because it needs to check for the pattern of the NEGATION of that for
FormValidator class to work. In other words, it must match the pattern
something like this:

! /<[^>]+>/

But the only way I can do this is to create a pattern and nothing
more; no other code of any kind except the literal pattern formed in
such a way to check for everything BUT a tag!

I also cannot use str_replace and strip out the tags; I can't use
htmlentities and translate the tags.. the requirements are to FLAG the
user if a tag is found but by NOT using the pattern to find one, but
to ONLY use the pattern to find the NEGATION of finding one!!!

Mind bender, I know.


Hm, another "negative-match without using !" post - just had one on
comp.lang.php:

http://groups.google.co.uk/groups?th=d73f7921f5435073

Are you using POSIX regexes (ereg_*) or Perl-compatible (preg_*)? If
Perl-compatible, then a negative lookahead?

/^(?!.*<.*>)/

Start of string, NOT followed by zero or more characters with a '<' after
them, then zero or more chars, then a '>'.

(There's probably a neater way of doing it, this is just the first that comes
to mind)

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #2
/^[^<>]+$/

did i get you right?

"Phil Powell" <so*****@erols.com> wrote in message
news:1c**************************@posting.google.c om...
I am having to use an existing FormValidator class to check form
elements, and one of the things I must check is to see if someone
entered tags in the string <>; if so, it must flag for that.

However, the catch is that, the way FormValidator class is written, I
can't use this pattern:

/<[^>]+>/

because it needs to check for the pattern of the NEGATION of that for
FormValidator class to work. In other words, it must match the pattern
something like this:

! /<[^>]+>/

But the only way I can do this is to create a pattern and nothing
more; no other code of any kind except the literal pattern formed in
such a way to check for everything BUT a tag!

I also cannot use str_replace and strip out the tags; I can't use
htmlentities and translate the tags.. the requirements are to FLAG the
user if a tag is found but by NOT using the pattern to find one, but
to ONLY use the pattern to find the NEGATION of finding one!!!

Mind bender, I know.

HELP!

Phil

Jul 17 '05 #3
Andy Hassall <an**@andyh.co.uk> wrote in message news:<4v********************************@4ax.com>. ..
On 29 Jan 2004 11:21:23 -0800, so*****@erols.com (Phil Powell) wrote:
I am having to use an existing FormValidator class to check form
elements, and one of the things I must check is to see if someone
entered tags in the string <>; if so, it must flag for that.

However, the catch is that, the way FormValidator class is written, I
can't use this pattern:

/<[^>]+>/

because it needs to check for the pattern of the NEGATION of that for
FormValidator class to work. In other words, it must match the pattern
something like this:

! /<[^>]+>/

But the only way I can do this is to create a pattern and nothing
more; no other code of any kind except the literal pattern formed in
such a way to check for everything BUT a tag!

I also cannot use str_replace and strip out the tags; I can't use
htmlentities and translate the tags.. the requirements are to FLAG the
user if a tag is found but by NOT using the pattern to find one, but
to ONLY use the pattern to find the NEGATION of finding one!!!

Mind bender, I know.
Hm, another "negative-match without using !" post - just had one on
comp.lang.php:

http://groups.google.co.uk/groups?th=d73f7921f5435073

Are you using POSIX regexes (ereg_*) or Perl-compatible (preg_*)? If
Perl-compatible, then a negative lookahead?

/^(?!.*<.*>)/

Start of string, NOT followed by zero or more characters with a '<' after
them, then zero or more chars, then a '>'.


I'm sorry I'm not familiar with the '?' used in this manner. Could
you provide some docs for me to read up more on it, I've never seen
'?' used in any other way other than as "0 or 1 instance of
something".

Thanx
Phil

(There's probably a neater way of doing it, this is just the first that comes
to mind)

Jul 17 '05 #4
On 30 Jan 2004 00:38:07 -0800, so*****@erols.com (Phil Powell) wrote:
I'm sorry I'm not familiar with the '?' used in this manner. Could
you provide some docs for me to read up more on it, I've never seen
'?' used in any other way other than as "0 or 1 instance of
something".


(? is the start of several constructs; this one is (?! - zero-width
negative look-ahead assertion.

See the manual: http://uk.php.net/manual/en/pcre.pattern.syntax.php

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #5
Andy Hassall <an**@andyh.co.uk> wrote in message news:<nq********************************@4ax.com>. ..
On 30 Jan 2004 00:38:07 -0800, so*****@erols.com (Phil Powell) wrote:
I'm sorry I'm not familiar with the '?' used in this manner. Could
you provide some docs for me to read up more on it, I've never seen
'?' used in any other way other than as "0 or 1 instance of
something".


(? is the start of several constructs; this one is (?! - zero-width
negative look-ahead assertion.

See the manual: http://uk.php.net/manual/en/pcre.pattern.syntax.php

That was more than I could absorb. Do you have a much easier site to
learn how ?! and all work? I believe they are called "lookaheads" or
something.

Phil
Jul 17 '05 #6
On 31 Jan 2004 11:52:43 -0800, so*****@erols.com (Phil Powell) wrote:
That was more than I could absorb. Do you have a much easier site to
learn how ?! and all work? I believe they are called "lookaheads" or
something.


If you look for Perl regular expression tutorials they should be mostly
applicable, and are probably more widely available than looking for
PHP-specific ones.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #7
Thanx I looked at several of them online and I'm no closer to
understanding them than I was before I ever learned about them.
Technical retardation I'm afraid.

Phil

Andy Hassall <an**@andyh.co.uk> wrote in message news:<01********************************@4ax.com>. ..
On 31 Jan 2004 11:52:43 -0800, so*****@erols.com (Phil Powell) wrote:
That was more than I could absorb. Do you have a much easier site to
learn how ?! and all work? I believe they are called "lookaheads" or
something.


If you look for Perl regular expression tutorials they should be mostly
applicable, and are probably more widely available than looking for
PHP-specific ones.

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Lasse Edsvik | last post: by
5 posts views Thread by Donald Firesmith | last post: by
4 posts views Thread by Rakesh | last post: by
2 posts views Thread by news.microsoft.com | last post: by
7 posts views Thread by ojsimon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.