I have a config file that I need to parse out. I am trying to write a very simple expression to match the variable on each line that does NOT start with a # (comment) character.
Here is a sample text from that config file:
# --------------------------
# some comments go here...
# -------------------------
#SSCOutputGenerationSchedule = 2015-07-03:21:00 5,2015-07-03:22:30,2015-07-04:14:00,2015-07-04:19:00
SSCOutputGenerationSchedule = 2015-08-05:14:00,2015-08-05:19:00,2015-08-10:15:30,2015-08-16:10:00
I want to match the SSCOutputGenerationSchedule variable on the last line and skip all lines that start with #. Here is what I've tried:
^(?!#)(\([A-Za-z]*\))
I found that expression on-line somewhere. It uses a negative look-back feature, which I thought would give me what I need, but it doesn't seem to work in the regexpal.comtool that I'm using for testing. Neither does regex101.com tool so I think the expression needs work.
Any tips would be appreciated.
How do I skip lines that start with #
Moderator: General Moderators
Re: How do I skip lines that start with #
That regex won't match your example because it's looking for parentheses...
But you don't have to care about the #s at all because you're looking for a [A-Za-z] variable.
But you don't have to care about the #s at all because you're looking for a [A-Za-z] variable.
Code: Select all
^[A-Za-z]+Re: How do I skip lines that start with #
Sorry, it still doesn't match anything - I tried that expression in two different tools this morning. It looks like it should work at least partially. Even if it did work, it would also be matching words in the comments section above, which is undesirable.
Therefore, I really need to find a way to skip lines all-together that start with #:
Examine first char at beginning of each line, if not #, then proceed to match the words in that line (alphanumerics and underscores). This solution comes close.... but still need to make it skip the whole line with # in pos 1:
(?!#)[A-Za-z]*
Produces this result:
#SSCOpututGenerationSchedule = 2015-07-03:21:00 ,2015-07-03:22:30,2015-07-04:14:00
SSCOpututGenerationSchedule = 2015-07-05:14:00,2015-07-05:19:00,2015-07-10:15:30
Therefore, I really need to find a way to skip lines all-together that start with #:
Examine first char at beginning of each line, if not #, then proceed to match the words in that line (alphanumerics and underscores). This solution comes close.... but still need to make it skip the whole line with # in pos 1:
(?!#)[A-Za-z]*
Produces this result:
#SSCOpututGenerationSchedule = 2015-07-03:21:00 ,2015-07-03:22:30,2015-07-04:14:00
SSCOpututGenerationSchedule = 2015-07-05:14:00,2015-07-05:19:00,2015-07-10:15:30
Re: How do I skip lines that start with #
Anything.... please
Re: How do I skip lines that start with #
The pattern requinix provided is fine.
[text]php > $s1 = '#SSCOpututGenerationSchedule = 2015-07-03:21:00 ,2015-07-03:22:30,2015-07-04:14:00';
php > $s2 = 'SSCOpututGenerationSchedule = 2015-07-05:14:00,2015-07-05:19:00,2015-07-10:15:30';
php > $pattern = '/^[A-Za-z]+/';
php > var_dump(preg_match($pattern, $s1));
int(0)
php > var_dump(preg_match($pattern, $s2));
int(1)
php >[/text]
[text]php > $s1 = '#SSCOpututGenerationSchedule = 2015-07-03:21:00 ,2015-07-03:22:30,2015-07-04:14:00';
php > $s2 = 'SSCOpututGenerationSchedule = 2015-07-05:14:00,2015-07-05:19:00,2015-07-10:15:30';
php > $pattern = '/^[A-Za-z]+/';
php > var_dump(preg_match($pattern, $s1));
int(0)
php > var_dump(preg_match($pattern, $s2));
int(1)
php >[/text]
Re: How do I skip lines that start with #
Is there a "multiline" mode thing available? If so it probably needs to be enabled.
Re: How do I skip lines that start with #
Yes, one of the tools that I use does indeed have Multiline mode - I enabled it and it works! Thanks for that. Not sure what multi-line mode means but I'll look for it. THx again.
Re: How do I skip lines that start with #
It means that ^ and $ will match at the beginning and end of lines, rather than just at the beginning and end of the entire string.