Reputation: 12213
I'm looking for a regex to match a character 'a' and also the ten characters after it, no matter what they are. So if I have a string hello world a is a very nice letter
, it would match a is a very
.
Upvotes: 1
Views: 5390
Reputation: 30995
If you want to match that you can use this regex:
a.{10}
By the way, if you want to get the content of the 10 characters, you can use the capturing groups:
a(.{10})
Upvotes: 6
Reputation: 785058
You can use this regex:
x.{0,10}
x
- matched literal x
.{0,10}
matches 0 to 10 characters after x
However for simple task like this it is better to use string functions and avoid regex.
Upvotes: 1
Reputation: 16103
No need for a regex, just find the occurence of the X, and take 10 chars from there:
echo substr($string, strpos($string,'x'), 10);
String functions are extremely fast, compared to regexes. In case of simple string manipulation you should always go for the simple stringfunctions
Upvotes: 4