• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

Regular Expression Help

Couldn't find a topic specifically for this so I thought I'd ask people whose language thrives on regular expressions. I could probably figure it out but I don't use regex very much and am in a hurry, hence the 500 points.

I have a series of parameters like this:

"Param 1","Param 2","Param 3"

I need to strip out all commas that are contained within a parameter and replace them with something else.

Thanks
0
PureNuts
Asked:
PureNuts
1 Solution
 
TintinCommented:


$_='"Param, 1","Param,2","Param 3"';
s/("\w+),(\w+")?/\1\2/g;
print;

0
 
FishMongerCommented:
>> I need to strip out all commas that are contained within a parameter

Can you be a little more explicit?  Do you mean 1 perameter or all parameters?  If all params, then it could be as simple as:

s/"/something else/g;

If only one 1 pram, then you need to tell us which one so we can provide the proper answer.
0
 
PureNutsAuthor Commented:
Sorry, I thought It was fairly obvious.

I need to strip out all commas from an indeterminate number of parameters.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
manav_mathurCommented:
use strict ;
use warnings ;
use Text::ParseWords ;
while(<DATA>) {
my @params = &parse_line(',',1,$_) ;
s/,/_/g for @params ;
##replace underscore above with whatever you want to substitute with
print join ",",@params ;
}

__DATA__
"Param ,, 1","Pa,ra,m 2","Par,,am 3"
0
 
TintinCommented:
PureNuts.

It's not that obvious as your description and sample data conflict.

You originally said:

[quote]
I have a series of parameters like this:

"Param 1","Param 2","Param 3"

I need to strip out all commas that are contained within a parameter and replace them with something else.
[/quote]

The data you supplied as no commas contained within a parameter.  However, I took your problem from your description and produced a regex that satisfies that description.  Did you mean something else?
0
 
ozoCommented:
What distinguishes a comma contained within a parameter from a comma between parameters?
Or did you mean

@parameters = "Param 1","Param 2","Param 3";
s/,/_/g for @parameters;
0
 
PureNutsAuthor Commented:
as Manuv correctly deduced:

"Param ,, 1","Pa,ra,m 2","Par,,am 3"

His suggestion seems to work but I want to reward tintin because he answered my original, poorly worded, question.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now