Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pattern matching a group of lines that are commented out

Status
Not open for further replies.

rafiu

Programmer
Jul 3, 2007
14
US
do anyone know the best way to capture pattern match and capture the data from the begining of a delimeter to the end of the delimeter.
see sample data below



/* its a marvelous day and the weather is warm
now is the time to settle our differences
and embrace each other with one love */

I HAVE COUPLE OF THIS DATA IN COUPLE FILES THAT I WILL LIKE TO GREP. COULD YOU PLEASE HELP? THANKS
 
You might want to check out this faq entry:

perlfaq6 - How do I use a regular expression to strip C style comments from a file?

Code:
[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]strict[/green][red];[/red]

[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$data[/blue] = [url=http://perldoc.perl.org/functions/do.html][black][b]do[/b][/black][/url] [red]{[/red][url=http://perldoc.perl.org/functions/local.html][black][b]local[/b][/black][/url] [blue]$/[/blue][red];[/red] <DATA>[red]}[/red][red];[/red]

[olive][b]if[/b][/olive] [red]([/red][blue]$data[/blue] =~ [red]m{[/red][purple]/[purple][b]\*[/b][/purple][purple][b]\s[/b][/purple]*(.*?)[purple][b]\s[/b][/purple]*[purple][b]\*[/b][/purple]/[/purple][red]}[/red][red]s[/red][red])[/red] [red]{[/red]
	[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [blue]$1[/blue][red];[/red]
[red]}[/red]

[teal]__DATA__[/teal]
[teal]do anyone know the best way to capture pattern match and capture the data from the begining of a delimeter to the end of the delimeter.[/teal]
[teal]see sample data below[/teal]

[teal]/* its a marvelous day and the weather is warm[/teal]
[teal] now is the time to settle our differences[/teal]
[teal]and embrace each other with one love */[/teal]

[teal]I HAVE COUPLE OF THIS DATA IN COUPLE FILES THAT I WILL LIKE TO GREP.  COULD YOU PLEASE HELP?  THANKS[/teal]
[tt]------------------------------------------------------------
Pragmas (perl 5.8.8) used :
[ul]
[li]strict - Perl pragma to restrict unsafe constructs[/li]
[/ul]
[/tt]

- Miller
 
Its close but not quite right. I will like to exclude any data inside the comments and pattern match the rest of the data. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top