how to check if 160th character of every line is 'Z' ?
-
how to check if 160th character of every line is ‘Z’ ?
-
So that implies that you want to find lines where the 160th character is NOT a
Z
?You could do that with:
find:
^(?-is).{159}(?!Z)
mode: regular expression -
@alan-kilborn Actually I want to find lines where the 160th character is a ‘Z’ character
-
find:
^(?-is).{159}(?=Z)
-
@alan-kilborn You are a genius ! it worked …Thank you so much
-
@alan-kilborn is there any way to 1) find lines where the 160th character is a ‘Z’ character and 130th character/digit is 0 2) find lines where the 160th character is a ‘Z’ character or 130th character/digit is 0
-
See the FAQ which notes:
Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first few (one to three) data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.
But as your second freebie:
You asked
160th character is a ‘Z’ character and 130th character/digit is 0
As with any regex, this can be done in multiple ways.
One way would be to do 129 of any character (where the
.
that Alan showed means “match any character”, and the{###}
that Alan showed is the multiplying operator to show how many copies of the previous token should be matched), then a0
, then 29 of any, then aZ
:^(?-is).{129}0.{29}
But since you’re also asking for an OR version, another way to do AND is with two separate lookaheads:
^(?-is)(?=.{129}0)(?=.{159}Z).*$
which says, match case-sensitive with.
not matching newline, such that the line is required to have 129 characters from the beginning followed by a 0, and the line is required to have 159 characters from the beginning followed by a Z; then use.*$
to match the whole line (because if your entire match is in (?=…) lookaheads, it will be a confusing zero-width match.160th character is a ‘Z’ character or 130th character/digit is 0
The OR version is to wrap the two lookaheads with an OR control inside a group:
^(?-is)(?:(?=.{129}0)|(?=.{159}Z)).*$
– which says, from beginning of line, case sensitive,.
not match newline, matching either 129-then-0
or 159-then-Z
or both, then grab the whole line. -
Additional helpful information for combining search criteria is found HERE.