Where do I place the pattern to allow dot in a regular expression?

Viewed 32

I'm not the greatest when it comes to Regex. I found one that fullfills my requirements, but I also need it to allow dot (only one and in the end of a sentence).

The regex is this one: /^[a-zA-ZÀ-ÿ\u00f1\u00d1]+(\s*[a-zA-ZÀ-ÿ\u00f1\u00d1]*)*[a-zA-ZÀ-ÿ\u00f1\u00d1]+$/

If possible, could someone send me the same regex, but with the mentioned conditions?

Regards,

Cristian.

1 Answers

Change this:

/^[a-zA-ZÀ-ÿ\u00f1\u00d1]+(\s*[a-zA-ZÀ-ÿ\u00f1\u00d1]*)*[a-zA-ZÀ-ÿ\u00f1\u00d1]+$/

To this to allow an optional dot at the end of the sentence:

/^[a-zA-ZÀ-ÿ\u00f1\u00d1]+(\s*[a-zA-ZÀ-ÿ\u00f1\u00d1]*)*[a-zA-ZÀ-ÿ\u00f1\u00d1]+\.?$/

Explanation: \.? is an escaped dot, the question mark makes it optional.

Related