-5

I want the regular expression of the following pattern

Rule

  1. The pattern should have no no punctuation except +. No blank spaces are allowed.Only alphabetical characters are allowed.

  2. The patter should be of two or more characters

EDIT:

I am thinking something like:

'^\w\w+ |[ \w\w+ + \w\w+] $' 

But it is not working.

piby180
  • 388
  • 1
  • 6
  • 18

1 Answers1

2

Your question has very limited detail, however the very simple answer is:

^[+]{2,}$

However, that would only match the character "+" 2 or more times. Since you're saying punctuation, it seems to imply that you want to allow other text. In that case, I would go with:

^[\w+ ]{2,}$

Which would allow all "word characters" and spaces. In the Python string, you will need to escape the backslash with another backslash.
If you want to experiment with regex strings, I would highly recommend the website http://regex101.com

EDIT: I have now seen your updated question, and to only have alphabetical characters and the plus symbol, you will want

^[A-Za-z+]{2,}$
Sam
  • 178
  • 2
  • 11
  • 1
    You don't have to escape the backslash if you use a raw string `r'^[\w+ ]{2,}$'` – Ben Nov 08 '15 at 10:59