-3

I need a pattern that matches any set of letters, numbers and underscore bounded by whitespace, . or :.

Blorgbeard
  • 93,378
  • 43
  • 217
  • 263
user3851593
  • 25
  • 1
  • 8

2 Answers2

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+[ .:]+$
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
    I have no idea what you're talking about. – zx81 Jul 21 '14 at 02:28
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
  • 296
  • 4
  • 16