Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to find data in specific column of a line

I'm trying to search a document for data on a specific column. I am trying to use:

^.{x}[data to find]

where x is the number of columns I want - 1.

I'm not sure if I am doing something wrong, or if my regex engine does not support that syntax. I am trying to use Notepad++, if that is helpful.

like image 460
Howler Avatar asked Feb 17 '09 16:02

Howler


1 Answers

Update 2013-2014 (4-5 years later)

As mentioned by Alan Moore in the comments

Notepad++ v6.x has real regex support via the PCRE library

See "How to use regular expressions in Notepad++ (tutorial)" (Multiplying operators)


Original answer (February 2009)

I just checked with the latest Notepad++5.2 and its regexp feature.

I confirm it does not have any repetition operator {min,max} which would have allowed you to specify how many times a token can be repeated.

http://1.bp.blogspot.com/_RrGIVCQs3RU/SHbq1B0wYlI/AAAAAAAAALI/h21UEYMEivc/s400/np%2B%2Breplace.png

An alternative would be:

.... [repeat '.' as many time as the number of column you want] ...[data to find]

You do not need ^: by default, Notepad++ regexps are applied line-by-line, and the . does not match eol characters (\r or \n)


As Asmor mentions in the comments:

Notepad++, for all its great features, uses Scintilla and inherits Scintilla's regex processing, with its limited regex features.

You say that "by default" regexes are applied line by line. This implies that you can set it otherwise, but to the best of my knowledge (and please, I beg you, prove me wrong!), there's no way to make multi-line regexes.

(I agree, and that is a major limitation)

Another limitation of Scintilla, the ^ operator is actually important, as it anchors the regex to the beginning of the line. Say you wanted to match 3 in the third column. You would want ^..3, and ..3 would match 3 in any column past the second.

like image 110
VonC Avatar answered Nov 05 '22 03:11

VonC