Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx to find first Tab in each line in a block of text

Tags:

regex

Hi all and thanks in advance,

I need a regex that will land me on the first tab in each line.

For instance

Romania RO  ROU 642
Russian Federation  RU  RUS 643
Rwanda  RW  RWA 646
Saint Barthelemy    BL  BLM 652

Should be parsed like this

Romania[*]  RO  ROU 642
Russian Federation[*]   RU  RUS 643
Rwanda[*]   RW  RWA 646
Saint Barthelemy[*] BL  BLM 652

all other tabs in the same line should be ignored.

like image 653
Sandy DeLeon Avatar asked Oct 20 '25 09:10

Sandy DeLeon


2 Answers

Try this but ensure to set a Multi-line option in whichever language you are using:

^[^\t]*(\t{1}).*$
like image 82
Barry Kaye Avatar answered Oct 21 '25 21:10

Barry Kaye


Here you go

Pattern

(^.*?)(\t)

Replace with

$1[*]$2

Use the modifier that lets ^ and $ match at line breaks.

Let me know if you got any more questions.

Regards, Tom

like image 34
buckley Avatar answered Oct 21 '25 22:10

buckley



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!