I have a line that looks like this:
$/Reporting/MSReportin gServices/Alle gro/Ex eXYZ.All egro.Ss rs:
The spaces are tabs, so here is what it actually looks like
$/Reporting/MSReportin gServices/Alle{TAB}gro/Ex{TAB}eXYZ.All{TAB}egro.Ss{TAB}rs:
I have to find the first tab in each line that sta开发者_如何学运维rts with a $
sign.
How do I do this using RegEx?
^\$(.*?)\t
Captures the text before the first tab. The length of the captured text plus one (for the dollar) tells you the index of the tab.
Here is a way to retrieve the first tab and replace it :
#!/usr/bin/perl
use strict;
use warnings;
my $s = qq!\$/Reporting/MSReportin\tgServices/Alle\tgro/Ex\teXYZ.All\tegro.Ss\trs:!;
$s =~ s/^(\$[^\t]*?)\t/$1HERE_IS_THE_FIRST_TAB/;
print '$1 = ',$1,"\n";
print '$s = ',$s,"\n";
Output:
$1 = $/Reporting/MSReportin
$s = $/Reporting/MSReportinHERE_IS_THE_FIRST_TABgServices/Alle gro/Ex eXYZ.All egro.Ss rs:
But you have to be more specific about what's the meaning of find the first tab
I think this expression should do it: ^\$(/\w+/\w+)\t
精彩评论