Regex to check a string with presence of : (colon) and . (dot)

Mandviwala, Abdeali 21 Reputation points
2022-08-29T08:53:46.877+00:00

Hello,

I need to check the validation of format of a string for which i am planning to use Regex. Below is my string format

subject:Patient.name

and also for the presence of string in the below format:

subject.name

I need to validate the above formats exactly as they are. I am thinking of having two different regex for them.

Please suggest how can it be implemented using Regex.

Regards,
Abdi

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2022-08-29T09:21:03.147+00:00

    If letters and digits are allowed, then try this expression (for both cases):

    ^(\w+)(:\w+)?\.(\w+)$

    If digits should not be permitted, then use \p{L} instead of \w.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.