Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

Your Ad Here

Limitations of the Basic Syntax
 
Article Index
Limitations of the Basic Syntax
Page 2
Page 3
Page 4
 

  • Any regular expression followed by an expression of the type {min[,|,max]} is a regular expression composed of a variable number of instances of that regular expression. The min parameter indicates the minimum acceptable number of instances, whereas the max parameter, if present, indicates the maximum acceptable number of instances. If only the comma is available, no upper limit exists to the number of instances that can be found in the string. Finally, if only min is defined, it indicates the only acceptable number of instances.

  • Square brackets can be used to identify groups of characters acceptable for a given character position.

  • Let's start from the beginning. It's sometimes useful to be able to recognize whether a portion of a regular expression should appear at the beginning or at the end of a string. For example, suppose you're trying to determine whether a string represents a valid HTTP URL. The regex http:// would match both http://www.phparch.com, which is a valid URL, and nhttp://www.phparch.com, which is not (and could easily represent a typo on the user's part).

    By using the "^" special character, you can indicate that the following regular expression should be matched only at the beginning of the string. Thus, the regex ^http:// will create a match only with the first of the two strings.

    The same conceptalthough in reverseapplies to the end-of-string marker "$", which indicates that the regular expression preceding it must end exactly at the end of the string. For example, com$ will match "sams.com" but not "communication."

    The special characters "+" and "?" work similarly to the Kleene Star, with the exception that they represent "at least one instance" and "either zero or one instances" of the regex they are attached to, respectively.

    As I briefly mentioned earlier, having a "wildcard" that can be used to match any character is extremely useful in a wide range of scenarios, particularly considering that the "." character is considered a regular expression in its own right, so that it can be combined with the Kleene Star and any of the other modifiers. For example, the expression


    Tags: Add more tags...,
    This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
    Users' Comments (0)

    Comment an article
      Name
      E-mail
       Title
    Available characters: 4000
     Notify me of follow-up comments
    This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
    Enter what you see:

    No comment posted

    Wallpaper 34
    Statistic


    Last Post

     
    Top! Top!