Download presentation

Presentation is loading. Please wait.

1
Regular expression

2
Validation need a hard and very complex programming. Sometimes it looks easy but actually it is not. So there is a lot of time and efforts waste in this process. What is the solution? Regular expression (regex or regexp for short) is a special text string for describing a pattern. Pattern is an element repeat in a predictable manner. Automate Validation – Regular expression

3
Examples – All telephone numbers have the same form. – All real numbers have the same form. – All the names have the same form – So on. Two steps to use regular expression: 1.Learn how to write pattern in RE. 2.Passing RE to Library which give you the ability to use it in validity by automata theory. Cont.

4
\d or [0-9] A digit \D or [^0-9] A non-digit \s or [ \t\n\x0B\f\r] A whitespace character \S or [^\s] A non-whitespace character \w or [a-zA-Z_0-9] A word character \W or [^\w] A non-word character. Any character Note: everyone of those pattern represent only one thing one digit one character and so on. Simple Patterns

5
Fortunately java support Regular expression and give us a good library which compile the pattern and make you able to using in validation. regex = "\\d"; string1="3"; System.out.println( string1+string1.matches(regex)); Using Regular Expression in validation

6
As we say simple pattern only one thing Mostly we need more than one thing Ex: number of two digits This called complex which contain one or more simple with reputation Then we can write our example as \d\d What about five digits? One hundred digits This is illogical to repeat \d one hundred time we need new concept. Complex pattern

7
X? once or not at all X* zero or more times X+ one or more times X{n} exactly n times X{n,} at least n times X{n,m} at least n but not more than m times Where x is pattern Now we can write the previous example by \d{100} Repetition in Regx

8
Regex has two type of grouping – Group mean or (use [] to represent) – Group mean and (use () to represent) Examples – [abc] mean one character of set {a, b, c} – (abc) mean three characters follow each other – (\d[.])mean digit follow with dot like 1. and 2. Grouping

9
[a-z] one of small characters from a to z [A-Z] one of capital characters from A to Z [a-zA-Z] one of small characters from a to z or one of capital characters from A to Z [a-ck-z] one of small characters from a to c or one of small characters form k to z (mean one of small characters out characters group between c to k. [^abc] Any character except a, b, or c [a-z&&[def]] d, e, or f (intersection) Ranging in Regex

10
[a-z&&[^bc]] a through z, except for b and c: [ad-z] (subtraction) [a-z&&[^m-p]] a through z, and not m through p: [a-lq-z](subtraction) Cont.

Similar presentations

© 2019 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google