Can someone explain regex expressions? I need regex expression to allow only, numbers, letters, plus, minus and space. Both C# and Javascript.
Asked
Active
Viewed 3,382 times
-4
-
#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 Answers
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:
Use the explain tab to work out your specific case and learn a bit as well.
Jason Sooter
- 49
- 6