SlideShare a Scribd company logo
Masudul Haque
•

A Regular expression is a pattern describing a
certain amount of text.

•

A regular expression, often called a pattern, is
an expression that describes a set of strings.
- Wikipedia
•
•
•
•
•
•

Matching/Finding
Doing something with matched text
Validation of data
Case insensitive matching
Parsing data ( ex: html )
Converting data into diff. form etc.






Pattern: To create a pattern, you must first invoke
one of its public static compile methods, which
will then return a Pattern object. These methods
accept a regular expression as the first argument.
Matcher: A Matcher object is the engine that
interprets the pattern and performs match
operations against an input string.
PatternSyntaxException: A PatternSyntaxException
object is an unchecked exception that indicates a
syntax error in a regular expression pattern.
Quote the next meta-character.

^

Match at the beginning

.

Match any character except new line

$

Match at the end, before new line

|

Alternation

()

Grouping

[]

Character class

{}

Match m to n times

+

One or more times

*

Zero or more times

?

Zero or one times
t
tab
n
newline
r
return
f
form feed
a
alarm (bell)
e
escape (think troff)
033
octal char
x1B
hex char
x{263a} long hex char
cK
control char
N{name} named Unicode character

(HT, TAB)
(LF, NL)
(CR)
(FF)
(BEL)
(ESC)
(example: ESC)
(example: ESC)
(example: Unicode SMILEY)
(example: VT)
Construct

Description

[abc]

a, b, or c (simple class)

[^abc]

Any character except a, b, or c (negation)

[a-zA-Z]

a through z, or A through Z, inclusive (range)

[a-d[m-p]]

a through d, or m through p: [a-dm-p] (union)

[a-z&&[def]]

d, e, or f (intersection)

[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)
Construct

Descriptions

.

Any character (may or may not match line terminators)

d

A digit: [0-9]

D

A non-digit: [^0-9]

s

A whitespace character: [ tnx0Bfr]

S

A non-whitespace character: [^s]

w

A word character: [a-zA-Z_0-9]

W

A non-word character: [^w]
Construct

Description

p{Lower}

A lower-case alphabetic character: [a-z]

p{Upper}

An upper-case alphabetic character:[A-Z]

p{ASCII}

All ASCII:[x00-x7F]

p{Alpha}

An alphabetic character:[p{Lower}p{Upper}]

p{Digit}

A decimal digit: [0-9]

p{Alnum}

An alphanumeric character:[p{Alpha}p{Digit}]

p{Punct}

Punctuation: One of !"#$%&'()*+,-./:;<=>?@[]^_`{|}~

p{Graph}

A visible character: [p{Alnum}p{Punct}]

p{Print}

A printable character: [p{Graph}x20]

p{Blank}

A space or a tab: [ t]

p{Cntrl}

A control character: [x00-x1Fx7F]

p{XDigit}

A hexadecimal digit: [0-9a-fA-F]

p{Space}

A whitespace character: [ tnx0Bfr]
Construct

Description

p{javaLowerCase}

Equivalent to java.lang.Character.isLowerCase()

p{javaUpperCase}

Equivalent to java.lang.Character.isUpperCase()

p{javaWhitespace}

Equivalent to java.lang.Character.isWhitespace()

p{javaMirrored}

Equivalent to java.lang.Character.isMirrored()
Construct

Description

p{IsLatin}

A Latin script character (script)

p{InGreek}

A character in the Greek block (block)

p{Lu}

An uppercase letter (category)

p{IsAlphabetic}

An alphabetic character (binary property)

p{Sc}

A currency symbol

P{InGreek}

Any character except one in the Greek block
(negation)

[p{L}&&[^p{Lu}]]

Any letter except an uppercase letter (subtraction)






Greedy quantifiers are considered "greedy" because they force the
matcher to read in, or eat, the entire input string prior to attempting
the first match.
Reluctant quantifiers, however, take the opposite approach: They
start at the beginning of the input string, then reluctantly eat one
character at a time looking for a match. The last thing they try is the
entire input string.
Possessive quantifiers always eat the entire input string, trying once
(and only once) for a match. Unlike the greedy quantifiers,
possessive quantifiers never back off, even if doing so would allow
the overall match to succeed.
Greedy

Reluctant

Possessive

Meaning

X?

X??

X?+

X, once or not at
all

X*

X*?

X*+

X, zero or more
times

X+

X+?

X++

X, one or more
times

X{n}

X{n}?

X{n}+

X, exactly n times

X{n,}

X{n,}?

X{n,}+

X, at least n times

X{n,m}+

X, at least n but
not more
than m times

X{n,m}

X{n,m}?
Construct

Description

^

The beginning of a line

$

The end of a line

b

A word boundary

B

A non-word boundary

A

The beginning of the input

G

The end of the previous match

Z

The end of the input but for the final terminator, if any

z

The end of the input
Capturing groups are a way to treat multiple
characters as a single unit.
 int groupCount()
 int start()
 int end()
 String group(int)
Backreferences
Constant

Equivalent Embedded Flag Expression

Pattern.CANON_EQ

None

Pattern.CASE_INSENSITIVE

(?i)

Pattern.COMMENTS

(?x)

Pattern.MULTILINE

(?m)

Pattern.DOTALL

(?s)

Pattern.LITERAL

None

Pattern.UNICODE_CASE

(?u)

Pattern.UNIX_LINES

(?d)
Index Methods

Index methods provide useful index values that show

precisely where the match was found in the input
string:
 public int start(): Returns the start index of the
previous match.
 public int start(int group): Returns the start index of
the subsequence captured by the given group during
the previous match operation.
 public int end(): Returns the offset after the last
character matched.
 public int end(int group): Returns the offset after the
last character of the subsequence captured by the
given group during the previous match operation.
Study Methods









Study methods review the input string and return a

boolean indicating whether or not the pattern is found.
public boolean lookingAt(): Attempts to match the input
sequence, starting at the beginning of the region, against
the pattern.
public boolean find(): Attempts to find the next
subsequence of the input sequence that matches the
pattern.
public boolean find(int start): Resets this matcher and then
attempts to find the next subsequence of the input
sequence that matches the pattern, starting at the
specified index.
public boolean matches(): Attempts to match the entire
region against the pattern.
Replacement Methods

Replacement methods are useful methods for replacing text in an

input string.
 public Matcher appendReplacement(StringBuffer sb, String
replacement): Implements a non-terminal append-and-replace
step.
 public StringBuffer appendTail(StringBuffer sb): Implements a
terminal append-and-replace step.
 public String replaceAll(String replacement): Replaces every
subsequence of the input sequence that matches the pattern
with the given replacement string.
 public String replaceFirst(String replacement): Replaces the first
subsequence of the input sequence that matches the pattern
with the given replacement string.
 public static String quoteReplacement(String s): Returns a literal
replacement String for the specified String. This method
produces a String that will work as a literal replacement s in
the appendReplacement method of the Matcher class.

More Related Content

What's hot

JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
Wingston
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
Knoldus Inc.
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
Sunil OS
 
Applets
AppletsApplets
Applets
SanthiNivas
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
NexThoughts Technologies
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
Java IO
Java IOJava IO
Java IO
UTSAB NEUPANE
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
Van Huong
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter09
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
Eng Teong Cheah
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
David Gómez García
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
WebStackAcademy
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
Emertxe Information Technologies Pvt Ltd
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
Sony India Software Center
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
Erhan Bagdemir
 
JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and Expressions
LearnNowOnline
 

What's hot (20)

JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
Applets
AppletsApplets
Applets
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Java IO
Java IOJava IO
Java IO
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and Expressions
 

Similar to Java: Regular Expression

Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaj Gupta
 
regular-expression.pdf
regular-expression.pdfregular-expression.pdf
regular-expression.pdf
DarellMuchoko
 
Regular Expression
Regular ExpressionRegular Expression
Regular ExpressionBharat17485
 
SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)
Logan Palanisamy
 
unit-4 regular expression.pptx
unit-4 regular expression.pptxunit-4 regular expression.pptx
unit-4 regular expression.pptx
PadreBhoj
 
js_class_notes_for_ institute it is very useful for your study.pdf
js_class_notes_for_ institute  it is very useful for your study.pdfjs_class_notes_for_ institute  it is very useful for your study.pdf
js_class_notes_for_ institute it is very useful for your study.pdf
Well82
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular Expressions
Mukesh Tekwani
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
MLG College of Learning, Inc
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracle
Logan Palanisamy
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
Muthuselvam RS
 
Regular_Expressions.pptx
Regular_Expressions.pptxRegular_Expressions.pptx
Regular_Expressions.pptx
DurgaNayak4
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
anjani pavan kumar
 
Regex1.1.pptx
Regex1.1.pptxRegex1.1.pptx
Regex1.1.pptx
VigneshK635628
 
regex.pptx
regex.pptxregex.pptx
regex.pptx
qnuslv
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
Sujith Kumar
 
16 Java Regex
16 Java Regex16 Java Regex
16 Java Regexwayn
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
Krishna Nanda
 

Similar to Java: Regular Expression (20)

Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
regular-expression.pdf
regular-expression.pdfregular-expression.pdf
regular-expression.pdf
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)SQL for pattern matching (Oracle 12c)
SQL for pattern matching (Oracle 12c)
 
unit-4 regular expression.pptx
unit-4 regular expression.pptxunit-4 regular expression.pptx
unit-4 regular expression.pptx
 
js_class_notes_for_ institute it is very useful for your study.pdf
js_class_notes_for_ institute  it is very useful for your study.pdfjs_class_notes_for_ institute  it is very useful for your study.pdf
js_class_notes_for_ institute it is very useful for your study.pdf
 
2.regular expressions
2.regular expressions2.regular expressions
2.regular expressions
 
Strings
StringsStrings
Strings
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular Expressions
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracle
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Regular_Expressions.pptx
Regular_Expressions.pptxRegular_Expressions.pptx
Regular_Expressions.pptx
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
 
Regex1.1.pptx
Regex1.1.pptxRegex1.1.pptx
Regex1.1.pptx
 
regex.pptx
regex.pptxregex.pptx
regex.pptx
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
16 Java Regex
16 Java Regex16 Java Regex
16 Java Regex
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
 

More from Masudul Haque

Websocket
WebsocketWebsocket
Websocket
Masudul Haque
 
Java 9 new features
Java 9 new featuresJava 9 new features
Java 9 new features
Masudul Haque
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
Masudul Haque
 

More from Masudul Haque (6)

Websocket
WebsocketWebsocket
Websocket
 
Java 9 new features
Java 9 new featuresJava 9 new features
Java 9 new features
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java-7: Collections
Java-7: CollectionsJava-7: Collections
Java-7: Collections
 
Java-7 Concurrency
Java-7 ConcurrencyJava-7 Concurrency
Java-7 Concurrency
 
Basic java
Basic javaBasic java
Basic java
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 

Recently uploaded (20)

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 

Java: Regular Expression

  • 2. • A Regular expression is a pattern describing a certain amount of text. • A regular expression, often called a pattern, is an expression that describes a set of strings. - Wikipedia
  • 3. • • • • • • Matching/Finding Doing something with matched text Validation of data Case insensitive matching Parsing data ( ex: html ) Converting data into diff. form etc.
  • 4.    Pattern: To create a pattern, you must first invoke one of its public static compile methods, which will then return a Pattern object. These methods accept a regular expression as the first argument. Matcher: A Matcher object is the engine that interprets the pattern and performs match operations against an input string. PatternSyntaxException: A PatternSyntaxException object is an unchecked exception that indicates a syntax error in a regular expression pattern.
  • 5. Quote the next meta-character. ^ Match at the beginning . Match any character except new line $ Match at the end, before new line | Alternation () Grouping [] Character class {} Match m to n times + One or more times * Zero or more times ? Zero or one times
  • 6. t tab n newline r return f form feed a alarm (bell) e escape (think troff) 033 octal char x1B hex char x{263a} long hex char cK control char N{name} named Unicode character (HT, TAB) (LF, NL) (CR) (FF) (BEL) (ESC) (example: ESC) (example: ESC) (example: Unicode SMILEY) (example: VT)
  • 7. Construct Description [abc] a, b, or c (simple class) [^abc] Any character except a, b, or c (negation) [a-zA-Z] a through z, or A through Z, inclusive (range) [a-d[m-p]] a through d, or m through p: [a-dm-p] (union) [a-z&&[def]] d, e, or f (intersection) [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)
  • 8. Construct Descriptions . Any character (may or may not match line terminators) d A digit: [0-9] D A non-digit: [^0-9] s A whitespace character: [ tnx0Bfr] S A non-whitespace character: [^s] w A word character: [a-zA-Z_0-9] W A non-word character: [^w]
  • 9. Construct Description p{Lower} A lower-case alphabetic character: [a-z] p{Upper} An upper-case alphabetic character:[A-Z] p{ASCII} All ASCII:[x00-x7F] p{Alpha} An alphabetic character:[p{Lower}p{Upper}] p{Digit} A decimal digit: [0-9] p{Alnum} An alphanumeric character:[p{Alpha}p{Digit}] p{Punct} Punctuation: One of !"#$%&'()*+,-./:;<=>?@[]^_`{|}~ p{Graph} A visible character: [p{Alnum}p{Punct}] p{Print} A printable character: [p{Graph}x20] p{Blank} A space or a tab: [ t] p{Cntrl} A control character: [x00-x1Fx7F] p{XDigit} A hexadecimal digit: [0-9a-fA-F] p{Space} A whitespace character: [ tnx0Bfr]
  • 10. Construct Description p{javaLowerCase} Equivalent to java.lang.Character.isLowerCase() p{javaUpperCase} Equivalent to java.lang.Character.isUpperCase() p{javaWhitespace} Equivalent to java.lang.Character.isWhitespace() p{javaMirrored} Equivalent to java.lang.Character.isMirrored()
  • 11. Construct Description p{IsLatin} A Latin script character (script) p{InGreek} A character in the Greek block (block) p{Lu} An uppercase letter (category) p{IsAlphabetic} An alphabetic character (binary property) p{Sc} A currency symbol P{InGreek} Any character except one in the Greek block (negation) [p{L}&&[^p{Lu}]] Any letter except an uppercase letter (subtraction)
  • 12.    Greedy quantifiers are considered "greedy" because they force the matcher to read in, or eat, the entire input string prior to attempting the first match. Reluctant quantifiers, however, take the opposite approach: They start at the beginning of the input string, then reluctantly eat one character at a time looking for a match. The last thing they try is the entire input string. Possessive quantifiers always eat the entire input string, trying once (and only once) for a match. Unlike the greedy quantifiers, possessive quantifiers never back off, even if doing so would allow the overall match to succeed.
  • 13. Greedy Reluctant Possessive Meaning X? X?? X?+ X, once or not at all X* X*? X*+ X, zero or more times X+ X+? X++ X, one or more times X{n} X{n}? X{n}+ X, exactly n times X{n,} X{n,}? X{n,}+ X, at least n times X{n,m}+ X, at least n but not more than m times X{n,m} X{n,m}?
  • 14. Construct Description ^ The beginning of a line $ The end of a line b A word boundary B A non-word boundary A The beginning of the input G The end of the previous match Z The end of the input but for the final terminator, if any z The end of the input
  • 15. Capturing groups are a way to treat multiple characters as a single unit.  int groupCount()  int start()  int end()  String group(int) Backreferences
  • 16. Constant Equivalent Embedded Flag Expression Pattern.CANON_EQ None Pattern.CASE_INSENSITIVE (?i) Pattern.COMMENTS (?x) Pattern.MULTILINE (?m) Pattern.DOTALL (?s) Pattern.LITERAL None Pattern.UNICODE_CASE (?u) Pattern.UNIX_LINES (?d)
  • 17. Index Methods Index methods provide useful index values that show precisely where the match was found in the input string:  public int start(): Returns the start index of the previous match.  public int start(int group): Returns the start index of the subsequence captured by the given group during the previous match operation.  public int end(): Returns the offset after the last character matched.  public int end(int group): Returns the offset after the last character of the subsequence captured by the given group during the previous match operation.
  • 18. Study Methods      Study methods review the input string and return a boolean indicating whether or not the pattern is found. public boolean lookingAt(): Attempts to match the input sequence, starting at the beginning of the region, against the pattern. public boolean find(): Attempts to find the next subsequence of the input sequence that matches the pattern. public boolean find(int start): Resets this matcher and then attempts to find the next subsequence of the input sequence that matches the pattern, starting at the specified index. public boolean matches(): Attempts to match the entire region against the pattern.
  • 19. Replacement Methods Replacement methods are useful methods for replacing text in an input string.  public Matcher appendReplacement(StringBuffer sb, String replacement): Implements a non-terminal append-and-replace step.  public StringBuffer appendTail(StringBuffer sb): Implements a terminal append-and-replace step.  public String replaceAll(String replacement): Replaces every subsequence of the input sequence that matches the pattern with the given replacement string.  public String replaceFirst(String replacement): Replaces the first subsequence of the input sequence that matches the pattern with the given replacement string.  public static String quoteReplacement(String s): Returns a literal replacement String for the specified String. This method produces a String that will work as a literal replacement s in the appendReplacement method of the Matcher class.