Variables and escaped characters in RegExp 
Author Message
 Variables and escaped characters in RegExp

Dear Perl Newsgroups goers,

I am attempting to strip out data from a few fields using a perl script.

The file I am parsing looks something like:

**Name (or alias):
**E-mail address:
**Age (optional):

and so on.

If someone fills out this text-only form, I want to take that data and put
it into a separate file.

I am trying to use some rudimentary regular expressions to do a pattern
match, something like:

$F_pname = "\*\*Name \(or alias\)\:";

while (<SHEET>)

        if ( /$F_pname/ ) {

                ...

        }

Quote:
}

However, when I run this I get the following error:

/**Name (or alias):/: ?+*{} follows nothing in regexp at ./psheet.pl line
43, <SHEET> line 1.  

I've figured out that it's the synbols: the *, (, ), and :.  If I escape
them directly in the expression (by using /\*\*Name \(or alias\)\:/ ) then
it works fine.  But using a variable makes the script choke.

Does anyone know what I can do?  If nothing else I won't use the variable
but using the variable makes my script more portable and easier to modify.
--
-- Arcana



Fri, 13 Jun 2003 03:43:40 GMT  
 Variables and escaped characters in RegExp

Quote:
> while (<SHEET>)

>         if ( /$F_pname/ ) {

if (/\Q$F_pname/) {


Sun, 15 Jun 2003 22:25:54 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. RegExp for escape characters

2. Regexp help, escaping characters

3. The match operator & variables containing regexp-characters

4. replacing characters with other characters, using regexp

5. regexp comments (escape?)

6. Question on regExp and Escape Sequences

7. regexp ?: how to ignore escaped delimiter?

8. Formats: Escaping Characters

9. CGI hangs due to dodgy escape character

10. problems with the \n escape character

11. Escaping cursor characters

12. how do I retranslate escaped characters

 

 
Powered by phpBB® Forum Software