The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Regex symbol for a tab
Discuss Regex symbol for a tab in the Regex Programming forum on Dev Shed. Regex symbol for a tab Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 20th, 2008, 08:03 AM
|
 |
Classical Computing
|
|
Join Date: May 2008
Location: Melbourne, Australia
|
|
|
Regex symbol for a tab
I love the idea of this new forum.
Today I tried using a PHP regex to validate basic HTML code in a textarea. I tested the regex by posting some valid HTML code but the regex kept rejecting it. I finally realized that there were some tabs in the HTML that were causing the problem. I'd like to keep the option of having tabs in the code.
So my question is, what's the best way to allow for a tab in a regex? I tried just typing a tab in the regex, and it worked, but it seems a poor way to go about it. I tried entering this tab symbol--& # 0 9 ; (without spaces, of course)--but that didn't work. Is there a better one, or is this just not Kosher anyway?
I'd love to know if anyone has any suggestions. I'm a newbie at this, and still using eregi, since I'm not confident about preg_match yet. If anyone knows of a really clear outline of the preg_match syntax I'd be grateful.
__________________
Simple is beautiful.
Last edited by Arem : August 20th, 2008 at 08:05 AM.
|

August 20th, 2008, 08:28 AM
|
|
|
|
\t is usually the way to do it.
|

August 20th, 2008, 08:38 AM
|
 |
kill 9, $$;
|
|
Join Date: Sep 2001
Location: Shanghai, An tSín
|
|
|
Yes, \t is for a tab. The whitespace character class (\s) will cover tabs along with other forms of whitespace (spaces, newlines, etc).
For the record I'm not a PHPer. In a Perl forum I would normally suggest that you not try to write regexps for parsing HTML (unless you're just practicing of course) but use a proper HTML parsing library. I guarantee it'll be easier and more reliable for you.
Regexps are not always the answer.
|

August 20th, 2008, 06:57 PM
|
 |
Classical Computing
|
|
Join Date: May 2008
Location: Melbourne, Australia
|
|
|
Thank you both very much for your replies. Much appreciated.
Now I am off to find out what an "HTML parsing library" is. Sounds interesting. (As I say, I'm very new at this...)
Best wishes.
|

August 20th, 2008, 07:15 PM
|
|
|
Here's one. I can't vouch for it as I've not had any needs to do HTML parsing, but it at least looks like it has some docs.
|

August 20th, 2008, 10:30 PM
|
 |
Classical Computing
|
|
Join Date: May 2008
Location: Melbourne, Australia
|
|
|
@ptr2void: Gracias! I'll try it out.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|