1

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?

Raj More
  • 47,048
  • 33
  • 131
  • 198
  • 1
    Find the first tab? Well, the first one **is** just a tab... :) Perhaps you want to find the index of the first tab? Or everything between `$` and the first tab? – Bart Kiers Sep 13 '10 at 14:09
  • @Bart K. I want to find the index of the first tab. I am using this in Editplus to edit a rather large file and remove tabs from only lines that start with a $ sign. – Raj More Sep 13 '10 at 16:48

3 Answers3

2
^\$(.*?)\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.

Timwi
  • 65,159
  • 33
  • 165
  • 230
1

I think this expression should do it: ^\$(/\w+/\w+)\t

splash
  • 13,037
  • 1
  • 44
  • 67
1

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

Toto
  • 89,455
  • 62
  • 89
  • 125