PureNuts
asked on
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
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
>> 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.
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.
ASKER
Sorry, I thought It was fairly obvious.
I need to strip out all commas from an indeterminate number of parameters.
I need to strip out all commas from an indeterminate number of parameters.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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?
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;
Or did you mean
@parameters = "Param 1","Param 2","Param 3";
s/,/_/g for @parameters;
ASKER
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.
"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.
$_='"Param, 1","Param,2","Param 3"';
s/("\w+),(\w+")?/\1\2/g;
print;