Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull out every comma, hyphen, underscore, space, and joining remaining words without spaces?

Tags:

regex

perl

I guess this would be a rather long regular expression, but is there a way to takeout underscores, spaces, commas, and hyphens from a string and then join the words together in perl?

Example:

_Car - Eat, Tree

Becomes:

CarEatTree
like image 937
tdjfdjdj Avatar asked Jan 27 '26 22:01

tdjfdjdj


2 Answers

You can use a simple substitution:

$string =~ s/[_ ,-]//g;
like image 92
Eugene Yarmash Avatar answered Jan 29 '26 13:01

Eugene Yarmash


This can also be done without regular expressions: Transliterate: tr///

use warnings;
use strict;

my $s = '_Car - Eat, Tree';
$s =~ tr/_ ,\-//d;
print "$s\n";

__END__

CarEatTree
like image 28
toolic Avatar answered Jan 29 '26 12:01

toolic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!