Reputation: 9
Would prefer if there is a way to use a regular expression to do this.
What I need to do is take a string such as "abc123xyz" search for "abc" then grab the next 3 characters which would be "123".
Any thoughts?
Thanks
Upvotes: 1
Views: 70
Reputation: 111850
(?<=abc)(.{3})
This will capture any three characters following abc
. (?<=abc)
is a lookbehind expression. Note that not all the regex engines support lookbehind expressions.
Upvotes: 2
Reputation: 12586
This regex would capture the three following characters after abc:
^abc(.{3})
If abc
is not positioned in the start of the string simply remove the ^
-character which indicates start of string.
Upvotes: 1