Regex to find data in specific column of a line

14,350

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.

Share:
14,350
Howler
Author by

Howler

I'm a computer geek in occupation and life.

Updated on June 05, 2022

Comments

  • Howler
    Howler over 1 year

    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.

  • Asmor
    Asmor about 12 years
    Notepad++, for all its great features, uses Scintilla and inherits Scintilla's regex processing. Here's a list of the features: scintilla.org/SciTERegEx.html It's a limited feature set relative to e.g. Perl, but it's better than some...
  • Asmor
    Asmor about 12 years
    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. Another limitation of Scintilla.
  • Asmor
    Asmor about 12 years
    (Sorry for all the comments, but I have three distinct points to make, and I figured multiple comments would be the best way) 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.
  • Alan Moore
    Alan Moore over 9 years
    Just so you know, Notepad++ v6+ has real regex support via the PCRE library.
  • VonC
    VonC over 9 years
    @AlanMoore Good point. I have included your comment in the answer for more visibility, as well as added some links to illustrate that new 6.x feature.