Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

26. Regular Expressions > Quantifiers

Quantifiers

Quantifiers match an item a specified number of times.

Quantifier

Meaning

*

Zero or more matches

+

One or more matches

?

Zero or one match

{n}

Exactly n matches

{n,}

At least n matches

{n,m}

Between n and m matches

The * quantifier matches the preceding character or group zero or more times. The following matches cv.doc, along with any numbered versions of the same file (e.g., cv2.doc, cv15.doc):

Console.Write (Regex.Match ("cv15.doc", @"cv\d*\.doc").Success);  // True

Notice that we have to escape out the period in the file extension with a backslash.

The following allows anything between cv and .doc and is equivalent to dir cv*.doc:

Console.Write (Regex.Match ("cvjoint.doc", @"cv.*\.doc").Success);  // True

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


 Â