tags:

views:

61

answers:

3

Hi,

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.

+1  A: 

Replace all newlines with space, then split the string with separator ANY_STRING.

KennyTM
The intention to use regular expression instead of some string functions is that I want to exploit the group function in regex afterward.
zyq524
@zyq524: Please edit your question to show what grouping you need.
KennyTM
+1  A: 

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.

ghostdog74
A: 

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.

yawn