-4

Can someone explain regex expressions? I need regex expression to allow only, numbers, letters, plus, minus and space. Both C# and Javascript.

unknown user
  • 19
  • 1
  • 5
  • #TeachMeRegEx [Learning Regular Expressions](http://stackoverflow.com/questions/4736/learning-regular-expressions) – Tushar May 30 '16 at 15:02
  • You didn't even try? – Thomas Ayoub May 30 '16 at 15:03
  • Letters = `[a-zA-Z]`, Numbers = `[0-9]`, Space `\s` or (space) & `-`, `+`. Combine them. **Hint:** All can be combined in the single character class(`[]`). – Tushar May 30 '16 at 15:04
  • Space is *ambiguous*. `\s` includes tabs, newlines, 0x20. Oh and depending on the engine and flags set, it might include even more! [See this answer](http://stackoverflow.com/questions/9291474/how-to-choose-between-whitespace-pattern/21067350#21067350) – HamZa May 30 '16 at 15:18

2 Answers2

1
[0-9A-Za-z\s+-]

0-9 -> numbers

A-Z -> capital letters

a-z -> lowercase letters

\s -> any whitespace character

Pokemon
  • 63
  • 1
  • 6
1

[a-zA-Z0-9/s+-]

Here's a start on Regexr.com:

http://regexr.com/3dh6t

Use the explain tab to work out your specific case and learn a bit as well.