04-03-2015 11:31 AM - edited 04-03-2015 11:44 AM
Can someone help me with this. I just need to find the first line in a file that doesn't start with, for simplicities sake, a.
I thought this would do it but it's not working.
^[^a.*\n]
04-03-2015 11:54 AM
^[^a\v]\V*
Make sure multiline? is true.
Find:
(1) beginning of a line
(2) something which is neither 'a' nor vertical whitespace (skip blank lines)
(3) 0 or more non-vertical-whitespace characters
04-03-2015 11:55 AM - edited 04-03-2015 11:57 AM
@GregFreeman wrote:
...find the first line in a file that doesn't start with, for simplicities sake, a.
...
Doesn't start with a...what? Doesn't start with a what!?
I think that ^[^a][^\n]*\n would work:
At the start of a line, a character that is not "a", followed by any number of character combinations that do not include a newline symbol, followed by a newline.
Edit: missed the ^ in the [^\n]
04-03-2015 12:18 PM
VItan a écrit :
@GregFreeman wrote:
...find the first line in a file that doesn't start with, for simplicities sake, a.
...
Doesn't start with a...what? Doesn't start with a what!?
I think that ^[^a][^\n]*\n would work:
At the start of a line, a character that is not "a", followed by any number of character combinations that do not include a newline symbol, followed by a newline.
Edit: missed the ^ in the [^\n]
This doesn't work, it will match a line that contain only \n followed by a line not starting with a (as an example \nbcd\n)
Ben64
04-03-2015 12:35 PM
@ben64 wrote:
This doesn't work, it will match a line that contain only \n followed by a line not starting with a (as an example \nbcd\n)
Ben64
Yup, it will find blank lines and following lines that do or do not start with "a". It will also include the line-feed character in the match.
Need to specify not "a" nor line-feed for the first character, similar to Darin.K's solution.
Also, \n is actually the escape code for a line-feed character in ASCII, correct? Then if you're working with ASCII data and you have CR as well as LF at the ends of your lines, you may actually get those characters in the match. Perhaps something like:
^[^a\n\r][^\n\r]*
would be more prudent unless \v is supported properly for your use, in which case use Darin.K's.
04-03-2015 01:13 PM
Greg,
For future use - I bought a copy of RegexBuddy (www.regexbuddy.com) to help with the (mercifully rare) occasions when I need to write some pattern matching, I can recommend it.
I have to be careful with regex notation, I can easily suffer a brain bleed if I try too hard to understand them.
(That's a joke.)
Dave