Regular Expressions (shortly RegEx, regexp or regex) are powerful that they allow you to take a piece of string inside a string by providing a valid pattern.

The code shown in this post are PCRE compatible that is one of the most common regex engines. Some codes may be compatible with other engines however this is not always the case.

Match exactly two characters (hyphen - here)

^[-]{2}$

Match anything between square brackets

(?<=\[)(.*?)(?=\])

Match a sign between curly braces

\{[^{}$]*\K\$(?=[^{}]*})

Source here.

Match a sign if outside of parentheses

\€(?![^\(]*\))

Example text:

This is €500 euros (not €300) and this is €250 euros (not €100).