Subset regular expression substitution

Nelson Ingersoll ningersoll at cso.atmel.com
Wed Feb 13 18:00:45 CST 2002


Greetings Fellow Mongers,

    I have a string which may, or may not, have parenthesis somewhere in 
the first 10 characters.  The string is always longer than 10 
characters.  I want to substitute space for either "(" or ")" or 
both.   Because that part of the string which beyond the tenth character is 
descriptive text, I dare not change any parenthesis after the first 10 
characters.  I understand the regex {$x =~ s/\(|\)/ /g;} matches any and 
all occurrences of either the '(' or ')' characters and replaces any '(' or 
')' with a space.

    The issue is, can I force the substitution, "s/\(|\)/ /g", to only work 
over the first 10 characters of $x rather than all characters?  Is this 
possible in a regex?   If not, I can always sub-string wing it.

    Your thoughts will be appreciated!

- Nelson ...

=====================================================================
Nelson E. Ingersoll             <> Sr. Principal Software Grunt
---------------------------------------------------------------------
ATMEL Corporation               <> Desk:     719-540-1263
Mail Stop 10240                 <> FAX:      719-540-6998
1150 E. Cheyenne Mtn Blvd.      <> Pager:    719-921-7917
Colorado Springs, CO  80906     <> INTERNET: ningersoll at cso.atmel.com
United States of America        <>           ningersoll at codenet.net
================== No good deed goes unpunished! ====================




More information about the Pikes-peak-pm mailing list