Thursday, December 22, 2011

Regular Expressions


Symbol Meaning or use 
^              # Assert position at the beginning of the string.
(?:            # Group but don't capture...
ISBN           # Match the text "ISBN".
(?:-1[03])?    # Optionally match the text "-10" or "-13".
:?             # Optionally match a literal ":".
\              # Match a space character (escaped).
)?             # Repeat the group between zero and one time.
(?=            # Assert that the following can be matched here...
[-0-9\ ]{17}$  # Match 17 hyphens, digits, and spaces, then the end
|              # of the string. Or...
[-0-9X\ ]{13}$ # Match 13 hyphens, digits, Xs, and spaces, then the
|              # end of the string. Or...
[0-9X]{10}$    # Match 10 digits and Xs, then the end of the string.
)              # End the positive lookahead.
(?:            # Group but don't capture...
97[89]         # Match the text "978" or "979".
[-\ ]?         # Optionally match a hyphen or space.
)?             # Repeat the group between zero and one time.
[0-9]{1,5}     # Match a digit between one and five times.
[-\ ]?         # Optionally match a hyphen or space.
(?:            # Group but don't capture...
[0-9]+         # Match a digit between one and unlimited times.
[-\ ]?         # Optionally match a hyphen or space.
){2}           # Repeat the group exactly two times.
[0-9X]         # Match a digit or "X".
$              # Assert position at the end of the string.

No comments:

Post a Comment