Reputation: 779
I need to make a regular expression to extract some strings.
The searching string could be like:
ANY_STRING(string1)this is
searching string1
ANY_STRING(string2)this is
searching string2
The match strings should be:
(string1)this is searching string1
(string2)this is searching string2
Any idea?
Thanks.
Upvotes: 0
Views: 315
Reputation: 342323
assuming your strings to search are always between the brackets and assuming you are on *nix
$ awk '{match($0,/\(/);printf "%s ", substr($0,RSTART)} !/\(/{print ""}' file
(string1)this is searching string1
(string2)this is searching string2
Otherwise, you should provide more concrete data.
Upvotes: 1
Reputation: 8214
Have a look at interactive evaluators for regular expressions e.g. the one at fileformat.info (for Java syntax) or rubular.com (Ruby syntax). Those might help you determine the expression you need.
Upvotes: 0
Reputation: 523214
Replace all newlines with space, then split the string with separator ANY_STRING
.
Upvotes: 1