I need a pattern that matches any set of letters, numbers and underscore bounded by whitespace, . or :.
Asked
Active
Viewed 37 times
-3
Blorgbeard
- 101,031
- 48
- 228
- 272
user3851593
- 27
- 1
- 9
-
Bounded on both sides? – zx81 Jul 21 '14 at 02:21
-
I'm not sure what you mean by that? – user3851593 Jul 21 '14 at 02:23
-
@user3851593 Welcome to Stack Overflow. Please consider bookmarking the [The Stack Overflow Regular Expressions FAQ](http://stackoverflow.com/a/22944075/2736496) for future reference. – aliteralmind Jul 21 '14 at 02:33
2 Answers
1
It sounds like you want something like this:
^[ .:]\w+[ .:]$
Explanation
- The
^anchor asserts that we are at the beginning of the string [ .:]matches one space char, period or colon\w+matches one or more letters, digits or underscore[ .:]matches one space char, period or colon- The
$anchor asserts that we are at the end of the string
Potential Tweaks
- In regex terms, "white-space" does not only mean the space characters, but also tabs, carriage returns and other forms of spacing. If this is what you mean, use
\sin place of the space inside[ .:] - If you want to allow more than one space character, colon or dot, you can tweak the regex like so:
^[ .:]+\w+[ .:]+$
zx81
- 41,100
- 9
- 89
- 105
-
I let my friend try it and he said it didn't work new.TextureID = Planet:GenerateRandomTexture() Should yielld new TextureId Planet GenerateRandomTexture – user3851593 Jul 21 '14 at 02:26
-
1
0
This is very simple. This should work:
([\s\d][ .:])+[\s\d]+
Basically the [\s\d] is the letters, numbers or underscores, and the [ .:] is the space, dot, or colon.
TheCoffeeCup
- 316
- 5
- 16