Also you might find it handy to include the capture group (e.g. $1 and so on). Then if you want you could include all three parts as it becomes alot easier as only one regex is needed to capture the three parts that you probably will need.
But as nakamura pointed out always use a regex tester before trying anything as it will save you so much hassle
I'd be willing to consider it, but how would you solve this using python - I'm used to sed (which is very close to perl). Python's regex requires me to know both regex and python - perl pretty much you just need to know regex.
There I changed the title to willing to consider Python - I'm language agnostic - as long as it can get the job done.
Thanks I'll check that out. Unfortunately, I still don't conceptually understand how to assign a variable to only the matching part of a regex from a string... nor can seem to come up with a solid google search which helps me understand.
@cotton@reikoshea example is what you want, but just to help you understand capture groups see code below.
#!/usr/bin/perl
# n2 - extract forename and surname
print "please enter your name ";
chop ($name = <STDIN>);
if ($name =~ /^\s*(\S+)\s+(\S+)\s*$/) {
print "Hi $1. Your Surname is $2.";
} else {
print "no match";
}
print "\n";
break it up into groups... 's/(\w{3})-(\d{4})-(\d{2}) \(\d{5}\)/$1-$2-$3-/g' each group is described by a $ and number so you basically remove the last 5 numbers and parenthesis. Hope this helps. Will work with Perl rename @cotton
rename -n 's/(\w{3})-(\d{4})-(\d{2}) \(\d{5}\)/$4/g' this will give you the numbers in parenthesis only.
Ok honestly - what the heck, are you guys seeing this???? If I show that to any "normal" person and told them it actually means something they'd tell me I'm crazy. I mean for gosh sakes - there's not even a number or letter in that thing.