Regular Expressions marked subexpression
Suppose I have a 10 letter word, say "HelloWorld". I want to recall 开发者_高级运维the first 5 characters ("Hello") separately and the complete 10 letters ("HelloWorld") separately within one single regular expression. Is there a way to do so by using a single RE only? I mean by using the "()" metacharacter.
Looking for:
/((.{5}).*)/
Though the first group will be the whole word, the second will be the partial.
Unless this is being broken down differently than an arbitrary number of characters
Here's a version using just the regular expression syntax supported by sed(1):
$ echo HelloWorld | sed 's/^\(.....\).*$/First: "\1" All: "&"/'
First: "Hello" All: "HelloWorld"
精彩评论