Shorthand class

Pattern Description
\d Matches any numeric digit. (0 to 9)
\D Matches any character but NOT numeric digit.
\w Matches a word character. (Any letter, numeric digit, or underscore)
\W Matches any character but NOT word character
\s Matches space, tab, or newline character
\S Matches any character but NOT space, tab, or newline character
. Any character
.* Any pattern
.*? Non-greedy match

Repetition options

Character Description
? Repetition zero or one time
* Repetition zero or more
+ Repetition one or more
{x} Repetition x number of time.
{x,y} Repetition between x or y times. (x,y inclusive)
{}? Non-greedy match

 

Begins with and ends with

^ Begins with the pattern. Eg. ^HeyThere
$ Ends with the pattern. Eg. Great$

 

Sets

[abc] Scans for a,b, or c from the text. note, it will not check for combination of these characters (Eg. ab)
[^abc] Scans any character other thanĀ  for a,b, or c
[a-zA-Z] Scans for letters between a to z and A to Z
[1-2][0-9] Scans for numbers between 10 to 29

Full stack Java Developer

   Buy me a coffee!

 

PayTM QR (INDIA)

Download file

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu