regex - Replace an asterisk (*) using Perl regular expression -


i have following string:

$_='364*84252';

the question is: how replace * in string else? i've tried s/\*/$i/, there error: quantifier follows nothing in regex. on other hand s/'*'/$i/ doesn't cause errors, doesn't seem have effect @ all.

something else weird here...

~> cat test.pl $a = "234*343"; $i = "foo";  $a =~ s/\*/$i/; print $a;  ~> perl test.pl 234foo343 

found something:

~> cat test.pl $a = "234*343"; $i = "*4";  $a =~ m/$i/; print $a;  ~> perl test.pl quantifier follows nothing in regex; marked <-- here in m/* <-- here 4/ @ test.pl line 4. 

solution, escape special characters variable using \q , \e, example (timtowtdi)

~> cat test.pl $a = "234*343"; $i = "*4";  $a =~ m/\q$i\e/; print $a;  ~> perl test.pl 234*343 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -