Search Multiple Columns
-
Here’s the expression I tried; ^.{41}TH1352.{56}100.{62}20220101.{154}D.{71}004 and here’s the data
. I tried breaking up the expression and do one at at time and it found all so positioning is correct so not sure why it doesn’t work, any help appreciated. -
Nobody wants to type your data from a screenshot so they can run a test on it.
Post TEXT data! -
Actual Data;
9996F48J999 NEWS HOOEY M219520713TH135226470000 10061 202201010004 20210406020210401 H13520022021033101N00000000.0000000.00MD
-
@Tom-Grisafe said:
^.{41}TH1352.{56}100.{62}20220101.{154}D.{71}004
9996F48J999 NEWS HOOEY M219520713TH135226470000 10061 202201010004 20210406020210401 H13520022021033101N00000000.0000000.00MD
Your regular expression matches your data so poorly that I think you’d better build it up one step at a time.
This will match the first part –
^.{33}TH1352
– do you understand why?After that there are two parts of it that match
100
. Which one do you want? -
@Tom-Grisafe said in Search Multiple Columns:
Actual Data;
9996F48J999 NEWS HOOEY M219520713TH135226470000 10061 202201010004 20210406020210401 H13520022021033101N00000000.0000000.00MD
But that’s not the actual data, as shown by your screenshot showing some sort of spacing:
You could have easily seen this in the PREVIEW window while entering your post – that should have indicated to you that maybe you needed to apply some sort of formatting in your post to better communicate the data. By doing a view source, I was able to find text that had extra spaces compared to what we could see, and I am hoping that data is closer to what you typed (but the Forum may still have edited it from what you originally typed).
On the other hand, if you had read the “Read This Before Posting” and “Template for Search/Replace Questions” that I linked you to earlier, you would have seen how to shown us your data like this:
9996F48J999 NEWS HOOEY M219520713TH135226470000 10061 202201010004 20210406020210401 H13520022021033101N00000000.0000000.00MD
which properly shows the spacing. The reason why I linked you to those was not because I like the typing; it’s because I knew that by following the advice in those posts, you could ask your question in a way that we could immediately understand, rather than making us dig for actual data or beg you to clarify.
With this version of your data, it puts the “100” in columns 57-59 like you originally said, so I believe this data actually represents what you have.
Now, to correct your misunderstanding with your attempted
^.{41}TH1352.{56}100
: the number in braces is not the column number. It is the number of repeats of the previous token in the regex. So my original^.{56}100.{12}004.{10}20220101
said “match the beginning of the line with^
, then 56 instances of any character.{56}
, follwed by the digits100
followed by 12 instances of any character.{12}
, etc”. Note that I didn’t have{56}
and{71}
in that expression to start the next token at columns 57 then at 72: I used.{56}
to consume 56 characters in the search, then match 3 characters in100
, then used.{12}
to move forward another 12 characters after the100
: 56+3+12=71 => so that’s why 71 characters were consumed. Thus, the004
matches the characters in columns 72-74.So, what your expression
^.{41}TH1352.{56}100
said was "start at the beginnning of the line, move forward 41 characters, then matchTH1352
(in columns 42-47), then move forward an additional 56 characters (through character 103), and then try to match100
in the next three characters (columns 104-106). Since your100
are in characters 57-59, not in 104-106, the regex you tried won’t match.Given that information, and what @Alan-Kilborn showed with the non-spaced version, please try again to modify my original to match your new requirements.
Notes:
^
is described in the “anchor” section of the Notepad++ Online User Manual’s regex docs.
is described in the “single character matches” section of the Notepad++ Online User Manual’s regex docs{##}
is described in the “mulitplying operators” section of the Notepad++ Online User Manual’s regex docs
-
@PeterJones said in Search Multiple Columns:
But that’s not the actual data
OMG, the effort it takes to answer these types of questions is more than it is worth.
-
@PeterJones @Alan-Kilborn Using the following data, I was able to get this formula to work; ^.{41}TH1352.{09}100.{03}20210401.{01}001.{80}B
99999999999 HOOOEY YOONNE M219520713TH135226470000 10061 202104010001 20210406020210401 H13520022021033101N00000000.0000000.00MB
If I am understanding correctly, the first parm {41} is the starting point and I just figured the nbr of pstns to the next field of 100 and so on etc… ?
** I apologize for not reading ahead of time in how to Post but appreciate all the Help !!
-
@Tom-Grisafe said in Search Multiple Columns:
If I am understanding correctly, the first parm {41} is the starting point
Hard for us to tell if you are understanding…
The
{41}
does not act alone. It acts with what comes to the left of it.
In this case.
comes to the left of it.
In regular expressions,.
(usually) means “any one character”.Because the
^
means start of line,.{41}
will "consume the first forty-one characters on a line, no matter what they are. Then if the next character is aT
you have the possibility of a match. And the expression grows from there.Get it?
-
Yes, makes sense. Pretty new to all the functionality in Notepad++, especially Reg Expressions so a little overwhelming but again appreciate the Help.
Any good site that completely explains Reg Expressions with Examples.
-
@Tom-Grisafe said in Search Multiple Columns:
Any good site that completely explains Reg Expressions with Examples.
Yes. The FAQ for regular expressions has plenty. I linked this to you already, in my first reply to you.