You can use it in various ways.
Let's suppose, you want to ensure that any user who is registering on your website, should only use alphabets in their username, then you can use this regular expression:
Now, if you want to make sure, that it should only contain, Alphabets, Numbers and Underscore. Then this is the expression you can use.
Explanation:
^ : start of string
[ : beginning of character group
a-z : any lowercase letter
A-Z : any uppercase letter
0-9 : any digit
_ : underscore
] : end of character group
* : zero or more of the given characters
$ : end of string
So, similarly you can make various combinations, Regex is very powerful, but a bit trick to understand at first. You can use some websites to generate the perfect regex for yourself.
https://regexr.com/
https://regex101.com/
Make sure you test by registering yourself, to ensure the regex is working properly, because a mis-configured regex configuration, can prevent your users from registering.
Hope this helps you.
Have a Great Day