This topic has been archived. It cannot be replied.
-
工作学习 / 专业技术讨论 / 请教一个PERL问题,如何把1, 23, "23,45.34", 334 中的, “,"同时去掉, 让它变成
1, 23, 2345.34, 334.
thanks.
-oasis(oasis);
2005-8-16
{95}
(#2454110@0)
-
the html messed up my previous answer, try this#!/usr/bin/perl
$tmpstr = '1, 23, "23,45.34", 334';
$tmpstr =~ s/"?(\d+),?(.*?)"?,?\s+/$1$2, /g;
print $tmpstr . "\n";
-super_unknown(mailman);
2005-8-16
{132}
(#2454256@0)
-
the backslashs in the regular expression were all stripped off by the php code, you need to add them back before digit (d) and space(s)
-super_unknown(mailman);
2005-8-16
(#2454284@0)
-
A neat and better solutionhttp://palapa.ocean.dal.ca/test/test.pl
1)find the delimiter, coma+space
2)inside optional inside double quote, it consists of two parts
mandatory base part, continuous digits ( parenthesis 1)
optional extension part , coma +
rest(digits,dot etc) (parenthesis 3)
3) replace the original with parenthesis 1 and parenthesis 3
-super_unknown(mailman);
2005-8-16
{359}
(#2454392@0)
-
Shortest way to do it: $s =~ s/[\." ]//g;
-bugfree(BugFree);
2005-8-16
(#2455050@0)
-
i'm sorry but your answer doesn't generate 1, 23, 2345.34, 334
-super_unknown(mailman);
2005-8-16
(#2455126@0)
-
oh, you need that ".", now you save another two bytes: $s =~ s/[" ]//g;
-bugfree(BugFree);
2005-8-16
(#2455129@0)
-
sorry pal, still wrong, your code generates 1,23,23,45.34,334, totally 5 numbers
-super_unknown(mailman);
2005-8-16
(#2455144@0)
-
sorry for my careless, here is the code your wanted: $s =~ s/ //g; s =~ s/"(\d+),(\d+)\.(\d+)"/\1\2\.\3/g;
-bugfree(BugFree);
2005-8-16
(#2455160@0)
-
the point of the question was "同时去掉", thus the desired answer is to do it in ONE regular expression
-super_unknown(mailman);
2005-8-16
(#2455165@0)
-
That the second one, the first one is to get rid of space: $s =~ s/"(\d+),(\d+)\.(\d+)"/\1\2\.\3/g
-bugfree(BugFree);
2005-8-16
(#2455213@0)
-
IMO the whole point is to do everything in ONE regular expression, but of course you have the right to differ. Anyway , time to end the discussion. Good experience talking to you.
-super_unknown(mailman);
2005-8-16
(#2455286@0)
-
the correct result of the original post only contains 4 numbers, read carefully
-super_unknown(mailman);
2005-8-16
(#2455151@0)