So I start my regex’s journey with this post. I have been postponing my experiment with regex for a long period of time. My methodology will be presenting some real and practical examples. Btw I m learning so please don’t criticize if you don’t like it or else do it who cares lol.

The first example will be a situation where you need to extract the function code from a given text (I will be using C Code) for extraction.

https://regex101.com/ is the online tool I will be using for the exercises.

Let me explain the regex here: ‘{‘ is a special character so we use ‘\’ before using it.

\s matches any whitespace character (equal to [\r

\t\f\v ]).

. * matches any character (except for line terminators)

\} matches the character } literally (case sensitive).

Now a user can write code this way also.

1st Capturing Group: ( \s | \w. * )

2nd Capturing Group: ( \s | \w. * )

1st Alternative \s ( \s matches any whitespace character (equal to [\r

\t\f\v ] )) 2nd Alternative \w. * ( \w matches any word character (equal to [a-zA-Z0-9_] )) In between 1st Alternative and 2nd Alternative I used ‘|’ (or operator).

The second example is a very simple example my surname is dabas some people write the correct one some write dabbas. We will be writing a regular expression that matches both

b {1,} matches the character b literally (case sensitive) {1,} Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed

The third example will be this one.

matches the alpha and The Alpha

The fourth example will be related to the beginning and ending.

Beginning:

^ asserts position at the start of a line

$ asserts position at the end of a line

The fifth one. Suppose you want to find a word but only with spaces.

\b asserts position at a word boundary

The Sixth example is a simple demonstration to extract GET parameters from HTTP Headers.