Click here to Skip to main content
12,397,059 members (64,691 online)
Click here to Skip to main content
Add your own
alternative version

Stats

16.4K views
39 bookmarked
Posted

Regex Quick Reference

, 25 Jun 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
A convenient Regex overview.

Characters - single character of a certain type

\w

word character

\W

non-word character

\d

digit

\D

non-digit

\s

whitespace

\S

non-whitespace

\r

carriage return

\n

line feed

\t

tab

[\b]

backspace

\x00[1]

character by hex value

 

 

Quantifiers - specify number of times to match

?

zero or one

{n[2]}

n times

*

zero or more

{n[3],}

n or more times

+

one or more

{n[4], m}

n to m times

Ranges - specify a range of accepted values

[ abc ]

a,b, or c

[^ abc ]

not a,b, or c

[a-c]

a, c, or anything in between

a|c

either a or c

Anchors - specify a certain position to match

\b

word boundary

\B

not word boundary

\<

start of word

\>

end of word

^

start of line

$

end of line

Assertions - match a pattern without consuming

(?=pat[5])

positive look-ahead

(?!pat)

negative look-ahead

(?<=pat)

positive look-behind

(?<!pat)

negative look-behind

Groups - multiple characters grouped together

(pat)

group with back-reference

(?<name>pat)

group with named back-reference

\n[6]

refer to a back-referenced group

(?:pat)

group without back-reference

Modifiers - specify how the regex engine searches

(?i:pat)

case insensitive

(?-i:pat)

case sensitive

(?s:pat)

dot matches newline

(?-s:pat)

dot does not match newline

(?x:pat)

ignore pattern spacing

Index

  • [1] a specific character’s hexadecimal value
  • [2] an integer greater than 0
  • [3] an integer greater than or equal to 0
  • [4] an integer greater than or equal to 0
  • [5] a RegEx pattern
  • [6] the index of a group in a RegEx pattern
  • [7] the index of a group in a RegEx pattern

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

FrostedSyntax
Web Developer JBHworks
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
gramacha26-Jun-13 2:51
membergramacha26-Jun-13 2:51 
Questiongud article Pin
harshal768926-Jun-13 1:48
memberharshal768926-Jun-13 1:48 
QuestionAbout some example. Pin
csharpbd26-Jun-13 1:21
membercsharpbd26-Jun-13 1:21 
QuestionBetter documentation-2 Pin
Prasad Khandekar25-Jun-13 21:54
professionalPrasad Khandekar25-Jun-13 21:54 
QuestionA better documentation Pin
morgex25-Jun-13 21:24
membermorgex25-Jun-13 21:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 26 Jun 2013
Article Copyright 2013 by FrostedSyntax
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid