Guharo Guharo - 3 months ago 22
C# Question

REGEX - Letters and symbols (C#)

Please I need help:

My regex:

/^[A-Za-z]*\\.?[A-Za-z_]*(?=A-Za-z_)/


I want the regex match with:
Start with letters, only one point, letters and underscores,finish with letters.
(No finish with underscore)

Example:


  • ABC.PROCEDURE_INSERT_USER

  • ZXYSQWE.PROCEDURE_LIST_PRODUCTS_COD_PROD_PRICE



Thanks for the help :)

Answer

I think this may help:

(?:^[a-zA-Z]*\\.[a-zA-Z_]*[a-zA-Z]$)

Start with a letter, then a dot, any combination of letters and underscore, and finish with a letter.

Instead checking if there is no underscore at the end, you know that always will be a letter. Its simplier to read.

You can see the regex test (with fixed issues you find) here: Regex101.com - Test