Page 1 of 1 1
Topic Options
#175125 - 2007-03-31 08:11 AM Regex Q & A
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4560
Loc: USA
For more reading on RegEx see these threads:
Input validation (thread that got me going)
RFC: Regular Expression UDFs
Regular Expression Basic Syntax Reference

All right Howard... now you've got me interested. I've added this as a personal goal to figure out.

One of your examples was to validate an IP address, using the following
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$
I also found the following that is supposed to do the same thing.
\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b

These may sound like a dumb questions but I'm not grasping the concept all that well. I'm assuming ^ and $ are defining the boundaries in your example and the \b's are defining the boundaries in the second. Is that correct? Second, why is it necessary to define the beginning and ending of a text range? Why wouldn't this work?
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}

Top
#175130 - 2007-03-31 01:46 PM Re: Regex Q & A [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Allen

Late for an appoinement, but this should get you started.. I RegEx!! They are the core of most of my "one-liners" in Unix scripting.

"^" and "$" are "anchors" - they effectively anchor the data to the beginning or end of the line. The RegEx string "^xyz" effectively means "any string beginning with 'xyz'", while "xyz$" means "any string ending with 'xyz'". If you use both of them together, as Howard did, it means "any string that IS 'xyz'" - you've anchored the beginning and end of the string.

I'd have to review the UDF again as the syntax is similar but not identical, likely due to reserved chars.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#175149 - 2007-04-02 03:37 AM Re: Regex Q & A [Re: Allen]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
\b Match a word boundary

If you are trying to match an IP address in a paragraph of text you would need to use the "\b". In my example I would assume that the input would onl;y be the IP address text. In this case as Glenn points out, I expect only the IP address. Without the ^ and $ to signify the beginning and end of the string, the user could entery "asc@#$100.200.103.45something else" and the RegEx would match.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 561 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.123 seconds in which 0.1 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org