regexeditplus

Regex Query to find the first tab before EOL


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 starts with a $ sign.

How do I do this using RegEx?


Solution

  • 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