473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Substitution problem

I need one help regarding regular expressions in PERL

I have a string like

test[01,02,03],tesst11*,rohit[01-20]

I need to write a regular expression for substitution which will make
this string like

test[01,02,03] tesst11* rohit[01-20]

that means I want to substitute only those commas by space which are
not in square brackets. Any quick idea..?

regards
Sharma
Oct 3 '06 #1
1 1355
sstouk
3
my($Str1) = 'test[01,02,03],tesst11*,rohit[01-20]';
my($Str2) = undef;
my(@array1) = undef;
my(@array2) = undef;

while ($Str1 =~ m!\[(.*?)\]!gis){push @array1,$1};
@array2 = split(/\[.*?\]/gis,$Str1);

for ($i = 0; $i < @array2; $i++)
{
$array2[$i] =~ s!,! !gis;
$Str2 .= $array2[$i]."[".$array1[$i+1]."]";
};

print "$Str2\n";
Oct 4 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Paddy | last post by:
Hi, I got tripped up on the way eval works with respect to modules and so wrote a test. It seems that a function carries around knowledge of the globals() present when it was defined. (The...
1
by: Ashok | last post by:
I am having some problem with the substitution operation. This is what I am trying to do: Get a directory path from the user and also the search string in the path and remove the string from the...
2
by: StopBsod | last post by:
Hi Group, I'm a newbie in XML and my problem/question should be quite simple to solve.... 1) an XML file with content like <location>file://path/to/something1</location>...
1
by: kollareddy | last post by:
Hi all, I am new to xml/xsd world. I want to know the differences between complex type and element being abstract and if both can be declared so, in case of substitution goups.Also can xsi:type...
4
by: Don | last post by:
I think "macro substitution" is the correct term for what I want to do, but, to be sure, here is a description of what I'd like to know is possible: I want to be able to create a create an object...
18
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
5
by: Murali | last post by:
In Python, dictionaries can have any hashable value as a string. In particular I can say d = {} d = "Right" d = "Wrong" d = "test" In order to print "test" using % substitution I can say
4
by: Ian | last post by:
Hi, Hopefully a simple question but my brain is hurting... I want to make a regex substitution, using search and replace patterns contained in variables. What I want to do is: $f =...
2
by: Steve | last post by:
Hi, I'm currently teaching myself about XML schems at the same time as specifying the XML document for a project I've been given to write. (I'm new to the XML world, so progress is a little slow...
2
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
In our application consisting of several custom user controls we want one of these controls to be excluded from the page cache. For this I tried to use the substitution control for output cache...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.