#175125 - 2007-03-31 08:11 AM
Regex Q & A
|
Allen
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
|
|
|
|
#175149 - 2007-04-02 03:37 AM
Re: Regex Q & A
[Re: Allen]
|
Howard Bullock
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.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 542 anonymous users online.
|
|
|