-1

My pattern must match a String that:

  • Can start with number
  • Can start with letters with accents or without accents too
  • Can't start with spaces
  • Can't start with special characters
  • Allow spaces between words
  • Do not accept special character except: - _ '

My current patter is: ^[^_\W][\p{L}\s0-9À-ÖØ-öø-ÿ.'-]+$

Valid examples:

Blockquote

João Antonio

João-Antonio

João's Company

Peter Müller

François Hollande

Patrick O'Brian

Silvana Koch-Mehrin

Invalid examples:

Company N@me

100% Company

\Company

\s Company

_Blockquote

Please help me!

Community
  • 1
  • 1

3 Answers3

0

First letter:

  • Start with number, letter
  • Exclude accents and special chars

[^\W_]

Rest of the text:

  • Include number, letter and accents
  • Include _, -, ' and

[0-9] & [A-Za-zÀ-ÖØ-öø-ÿ] & [_\-\' ]

Here you are:

^[^\W_][0-9A-Za-zÀ-ÖØ-öø-ÿ_\-\' ]+$

See this question

When you have to deal with complicated Regex, use the Regexr'!

Florian Fasmeyer
  • 795
  • 5
  • 18
  • This not work for me, my string must not start with special characters, spaces and whatever character different of numbers and letters. – Vinícius Carneiro de Brito Apr 07 '20 at 20:29
  • Hey, did you modify your valid examples? haha, _Blockquote was part of it! Whatever, I corrected my code for you. <3 But man, you MUST know how to use RegEx. This is basic knowledge you must have as a scientist. I know, it's not fun, bt you have to! PLEASE, USE https://regex101.com/ or https://regexr.com/. You will learn quickly and become a pro at it! – Florian Fasmeyer Apr 07 '20 at 22:43
  • Yes i modified and guy I asked because I needed help. – Vinícius Carneiro de Brito Apr 08 '20 at 12:28
0

My best was:

/^[^_\W][\p{L}\s0-9À-ÖØ-öø-ÿ.'-]+$/gi

Test: https://regexr.com/521r2

0

I think the requirements are not too clear but based on your examples:

^[a-zA-ZÀ-ÖØ-öø-ÿ][ '_-a-zA-ZÀ-ÖØ-öø-ÿ]+$


^                        = beginning of line
$                        = end of line
[a-zA-ZÀ-ÖØ-öø-ÿ]        = matches all these characters specified including one with accents
[ '_-a-zA-ZÀ-ÖØ-öø-ÿ]    = same as above except it includes the quote, blank space, underscore
+                        = one or more (greedy)

See this for more details and examples link

Best.

Khanna111
  • 3,627
  • 1
  • 23
  • 25