From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Still bad at regex

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]

0 Kudos
Message 1 of 6
(2,874 Views)

^[^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

0 Kudos
Message 2 of 6
(2,843 Views)

@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]



0 Kudos
Message 3 of 6
(2,840 Views)

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

0 Kudos
Message 4 of 6
(2,820 Views)

@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.



0 Kudos
Message 5 of 6
(2,802 Views)

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

David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer
Message 6 of 6
(2,785 Views)