Finding Last line in the text using regular expressions with .net

Finding Last line in the text using regular expressions with .net

In this regular expressions, we are going to find last line in the text.

Regular Expression Pattern

.+Z$

A description of the regular expression:

Any character, one or more repetitions
End of string or before new line at end of string
End of line or string

How It Works

This regular expression will check for Any character, one or more repetitions of End of string or before new line at end of string.

Continue reading “Finding Last line in the text using regular expressions with .net”

Finding First line in the text using regular expressions with .net

Finding First line in the text using regular expressions with .net

In this regular expressions, we are going to find first line in the text.

Regular Expression Pattern

\A.*

A description of the regular expression:

Beginning of string
Any character, any number of repetitions

How It Works

This regular expression will check for Beginning of line followed by Any character.

Continue reading “Finding First line in the text using regular expressions with .net”

Finding each line in the text using regular expressions with .net

Finding each line in the text using regular expressions with .net

In this regular expressions, we are going to find each line in the text.

Regular Expression Pattern

^.*$

A description of the regular expression:

Beginning of line or string
Any character, any number of repetitions
End of line or strin

Sucessful Matches

This is a test.
What you want?
That’s great!
as shown below:

Continue reading “Finding each line in the text using regular expressions with .net”

Finding Sentence using regular expressions with .net

Finding Sentence using regular expressions with .net

In the field of linguistics, a sentence —an expression in natural language— is often defined to indicate a grammatical and lexical unit consisting of one or more words that represent distinct concepts. A sentence can include words grouped meaningfully to express a statement, question, exclamation, request or command.

All the sentences contins group of words ending with .(punctuation mark), ?(question mark), !(exclamation mark) or : (colon) etc. In this regular expression we are going to find out sentences, means group of words ending with .(punctuation mark), ?(question mark), !(exclamation mark) or : (colon) etc.

Regular Expression Pattern

(?sx-m)[^\r\n].*?(?:(?:\.|\?|!|\:)\s)

A description of the regular expression:

Change options within the enclosing group [sx-m]
Turn OFF Multiline option
Turn ON Single Line option
Turn ON Ignore Pattern Whitespace option
Any character that is NOT in this class: [\r\n]
Any character, any number of repetitions, as few as possible
Match expression but don’t capture it. [(?:\.|\?|!|\:)\s]
(?:\.|\?|!|\:)\s
Match expression but don’t capture it. [\.|\?|!|\:]
Select from 4 alternatives
Literal .
Literal ?
!
Literal :
Whitespace

Continue reading “Finding Sentence using regular expressions with .net”

Finding Similar Words (like bat, cat, mat)using regular expressions with .net

Finding Similar Words (like bat, cat, mat)using regular expressions with .net

In this regular expression we are going to find out Similar Words like bat, cat, mat, and rat. Just take a look at above words they all same ending "at".

Regular Expression Pattern

\b[a-zA-Z](at\b)

A description of the regular expression:

First or last character in a word
Any character in this class: [a-zA-Z]
[1]: A numbered capture group. [at\b]
at\b
at
First or last character in a word

Continue reading “Finding Similar Words (like bat, cat, mat)using regular expressions with .net”