I need a pattern that matches any set of letters, numbers and underscore bounded by whitespace, .
or :
.
Asked
Active
Viewed 35 times
-3
![](../../users/profiles/369.webp)
Blorgbeard
- 93,378
- 43
- 217
- 263
![](../../users/profiles/3851593.webp)
user3851593
- 25
- 1
- 8
-
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
\s
in 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+[ .:]+$
![](../../users/profiles/1078583.webp)
zx81
- 38,175
- 8
- 76
- 97
-
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.
![](../../users/profiles/3841977.webp)
TheCoffeeCup
- 296
- 4
- 16