Click here to get back home

How to find this pattern by regular expression?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
How to find this pattern by regular expression? Ahmad 03-30-2008
Posted by Ahmad on March 30, 2008, 10:56 am
Please log in for more thread options
Hi,

I want to find the pattern: PATTERN that can contain lower case or
upper case characters, digits, and special characters like : _ ; ( )
& .

A sample context is:

-- Start here (this line is not in context)

PATTERN {
@ a line containing anything(comment line)
@ multiple comment lines can exist
// Another type of comments
/* Third type of comments
and it's a multiline comment
*/
x1=a AND b
y1= x1 OUTSIDE layer100
copy y1

//Comments can exist anywhere in the text (between the braces)

// this is the closing brace }

-- End here (this line is not in context)

I need when apply regular expression on the above sample context, it
return the word PATTERN.

Any guidance about the most efficient RE to perform that?

Thanks and best regards,
Ahmad

Posted by Gunnar Hjalmarsson on March 30, 2008, 12:14 pm
Please log in for more thread options
Ahmad wrote:
> I want to find the pattern: PATTERN that can contain lower case or
> upper case characters, digits, and special characters like : _ ; ( )
> & .
>
> A sample context is:
>
> PATTERN {
> @ a line containing anything(comment line)
> @ multiple comment lines can exist
> // Another type of comments
> /* Third type of comments
> and it's a multiline comment
> */
> x1=a AND b
> y1= x1 OUTSIDE layer100
> copy y1
>
> //Comments can exist anywhere in the text (between the braces)
>
> // this is the closing brace }

my ($pattern) = /([\w:;()&.]+)\s+/s;

> Any guidance about the most efficient RE to perform that?

Efficient? What makes you consider efficiency being an issue?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by Tad J McClellan on March 30, 2008, 4:29 pm
Please log in for more thread options
> Hi,
>
> I want to find the pattern: PATTERN that can contain lower case or
> upper case characters, digits, and special characters like : _ ; ( )
> & .


/[\w:;()&.]+/


> A sample context is:
>
> -- Start here (this line is not in context)
>
> PATTERN {
> @ a line containing anything(comment line)
> @ multiple comment lines can exist
> // Another type of comments
> /* Third type of comments
> and it's a multiline comment
> */
> x1=a AND b
> y1= x1 OUTSIDE layer100
> copy y1
>
> //Comments can exist anywhere in the text (between the braces)
>
> // this is the closing brace }
>
> -- End here (this line is not in context)
>
> I need when apply regular expression on the above sample context, it
> return the word PATTERN.


my($match) = $context =~ /(PATTERN)/;


> Any guidance about the most efficient RE to perform that?


You should first try to find ANY regex that does what you want.

Only if it proves to be too slow should you concern yourself with
making it faster.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Similar ThreadsPosted
Online Regular Expression Pattern Builder April 19, 2006, 12:41 am
Find replace : Regular expression June 12, 2007, 1:41 am
Trouble with Regualar Expression Pattern November 20, 2007, 7:13 pm
find a matching pattern in file and find it in another file too March 13, 2008, 1:13 am
Regular Expression help please October 4, 2004, 9:56 pm
Regular expression September 23, 2004, 11:53 am
Regular Expression for - \C\R... November 2, 2004, 11:15 am
regular expression help November 15, 2004, 8:36 pm
How to do this job with regular expression December 15, 2004, 4:13 pm
Regular Expression Help December 15, 2004, 1:56 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap