Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Dealing with Regexes for a specific replacement pattern

by gridlock (Novice)
on Feb 21, 2004 at 04:55 UTC ( #330767=perlquestion: print w/replies, xml ) Need Help??
gridlock has asked for the wisdom of the Perl Monks concerning the following question:

I've been dealing with this problem which has gotten me stumped - and I figure there has to be a way to do this simply with a regex rather than write a seperate function.... here's my jam...

I've had to deal with a stack of values who's occurrence is as follows:

AA40772C192C56C338C001C001CF1F4F3F2338C001C001CF1F2F3F8184C52C000

Now - the trifle is as follows.....
This is a stack of values that are all delimited by the character "C". However, for all fields beginning with "338" - there is no field delimiter - the values starting with 338 have a standard format as follows:

338C\d\d\dC\d\d\dC\S\S\S\S\S\S\S\S

What I want to do is replace this pattern with the same pattern with a C appended to it within the string... so I tried using the follwing regex:

s/338C\d\d\dC\d\d\dC\S\S\S\S\S\S\S\S /338C\d\d\dC\d\d\dC\S\S\S\S\S\S\S\S C/g

The only problem is.... although it inserts the "C" delimiters, the regex has wipes out the pertinent data of the digits and the "F"s - - is there a simple regex I can use to accomplish this? Any help will be much appreciated! Thanks is advance!
/Gridlock a.k.a. Debashis "Codito Ergo Sum"
  • Comment on Dealing with Regexes for a specific replacement pattern

Replies are listed 'Best First'.
Re: Dealing with Regexes for a specific replacement pattern
by jweed (Chaplain) on Feb 21, 2004 at 04:57 UTC
      Or even simpler:
      s/(338C\d{3}C\d{3}C\S{8})/$1C/g

      Abigail

        Thanks much! Appreciate it!
        /Gridlock a.k.a. Debashis "Codito Ergo Sum"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://330767]
Approved by jweed
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2018-01-17 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (194 votes). Check out past polls.

    Notices?