Hello I would like to have a regex which matches anything but the line ending with comma followed by 0 or more spaces. Please test it before giving me the solution. I initially thought it is easy and later felt difficult to solve it.
Example:
1) this is an example - should match
2) this is an example, - should not match
3) this is an example, - should not match
4) this is an example - should match
Thanks,
Mohamed
Guys,
The solutions you provided is using the control features from PERL language to match the other lines and isolate the required ones in the else block. I just wanted to have the regex matching in the if block itself and not in the else block.
For instance, we can check our regex in
this website to see its validness.
I can think of a solution which is close to Moritz solution.
My regex is ^(?!.*,\s*$)
The ?! is used for negative lookahead.
Do you guys think of any other alternatives to achieve this. Please don't use the programming construct. Just focus on the REGEX alone.
Thanks & Regards,
Mohamed
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.