Re: [PATCH] Add Hyperlinks, Add vim/gvim and add FAQ about negated regexps
[email protected] ("Shlomi Fish") Sun, 8 Jun 2008 17:19:55 +0300
| Newsgroups | perl.perlfaq.workers |
|---|---|
| Message-ID | <[email protected]> |
Hi! On Sun, Jun 8, 2008 at 2:14 AM, brian d foy <[email protected]> wrote: > In article > <[email protected]>, Shlomi > Fish <[email protected]> wrote: > >> I started to revamp the FAQ. My original intention was to add some >> questions from http://perl.net.au/wiki/Freenode_Sharp_Perl_FAQ , and >> other things the Freenode #perl people have encountered. > > You added a bunch of L<> markup, but in my hazy memory I think we were > trying to avoid those for some reason. Did you try a bunch of different > formatters with it? Was any of the output weird? Maybe Pod::Simple > fixed whatever used to be odd about it. Don't know. It's just that I was taught that one should use L<..> for hyperlinks. But maybe plain-URLs also work nicely. > > The hash merging question is a good one, but I'll rewrite the answer > for it. Thanks for the suggestion :) Thanks and you're welcome. :-) > >> http://perl.net.au/wiki/Freenode_Sharp_Perl_FAQ#How_can_I_match_anything-excep >> t-a-regex_inside_a_Perl_regular_expression.3F > > I don't understand the intent of this question. Is this something > people really ask? It seems that the answer should just use !~ (like it > finally mentions). What problem is this trying to solve? Yes people ask this on Freenode #perl all the time: {{{{{{{{{{{ Feb 10 20:36:18 <Zaba_> in regexes, I do [^something] to match anything but a specified character class, right? Feb 10 20:36:52 <rindolf> Zaba_: yes. Feb 10 20:37:04 <Zaba_> is it possible to match anything but a specific string in regexes? Feb 10 20:37:09 <rindolf> Zaba_: well, anything except that list of characters. Feb 10 20:37:31 <rindolf> Zaba_: that's very difficult. Feb 10 20:37:39 <rindolf> Zaba_: there's negative lookahead if that helps. Feb 10 20:38:19 <Zaba_> rindolf, I want what [^] does for specific characters, just for full strings Feb 10 20:38:21 <-- kidd2 has quit (Read error: 104 (Connection reset by peer)) Feb 10 20:38:21 <rindolf> Zaba_: the best way is probably to extract it and then use !~ or a negated index() check. Feb 10 20:38:30 <Zaba_> oh.. =/ }}}}}}}}}}} {{{{{{{{{{{{{ Jun 20 17:12:41 <eb1kenobi> is there no way to do negated constructs with regexes? like what I'm doing !#endif Jun 20 17:12:50 <eb1kenobi> cuz that does not work Jun 20 17:13:03 <Vareni> we just suggested that you not use regex. Jun 20 17:13:07 <rindolf> LordFrith: I think it also adds #line directives. Jun 20 17:13:10 <eb1kenobi> why not? Jun 20 17:13:21 <mernad> hi, are there any commands that can convert a hexdump in the format of "020066014C34" to original form? Jun 20 17:13:33 <eb1kenobi> otherwise it's lot's of coding Jun 20 17:14:04 <rindolf> eb1kenobi: it's not so much coding. Jun 20 17:14:16 <mernad> I apologize if this is not the type of place to ask, but I couldn't seem to find anything. Jun 20 17:14:30 <LordFrith> eb1kenobi: $state=1; while(<>){if($state==1){if(/#ifdef DEBUG/){$state=2;next;}print;}else{$state=1 if(/#endif/);}} Jun 20 17:15:00 <LordFrith> You may have to add some states to handle #ifdef's inside the degug section, but that's the approach I would use. Jun 20 17:15:14 <-- nipuL has quit (Remote closed the connection) Jun 20 17:15:30 <eb1kenobi> thnx Jun 20 17:15:40 * eb1kenobi [grmbl] Jun 20 17:16:30 <LordFrith> mernad: Do you mean convert that string into a decimal? Jun 20 17:16:31 <rindolf> eb1kenobi: it isn't possible to negate a regex, (not without writing a very complex regex that does that at least). There are negative look-aheads and look-behinds though, but they are relatively limited. Jun 20 17:16:56 <Limbic_Region> rindolf - careful with your verbiage Jun 20 17:16:59 <rindolf> LordFrith: I don't think your code handles #else's. Jun 20 17:17:02 <Limbic_Region> very simple to negate a regex Jun 20 17:17:11 <Limbic_Region> if ! $foo =~ /foo/ Jun 20 17:17:12 --> FlamingRain ([email protected]) has joined #perl Jun 20 17:17:15 <LordFrith> rindolf: No, it doesn't. That would be another state to add. Jun 20 17:17:18 <Limbic_Region> depending on what you mean by negation }}}}}}}}}}}}} {{{{{{{{{{{ Aug 19 11:42:16 <fridrik> What do I do if I want to match everything that does not match the following criteria: ^(inetnum): (.*?) - (.*?)$ Aug 19 11:42:21 <Zoffix> well since my uptime is gone I'm good put the helmet on and boot my Windows and make some music.... Aug 19 11:42:31 <fridrik> Basically need to reverse it Aug 19 11:42:36 <bpalmer> fridrik: say "if not /^(inetnum...)/" Aug 19 11:42:37 <fridrik> But I must reverse the regexp Aug 19 11:42:37 <hobbs> fridrik: invert the result of matching against that ;) }}}}}}}}}}} > >> That put aside, why was the comment about parsing XML and/or HTML >> disappear? > > What comment? Which question? I don't recall the particular edit, but > everything should be in the commit logs. Quoting: {{{{{{{{{{{{{ =head2 Can I use Perl regular expressions to match balanced text? X<regex, matching balanced test> X<regexp, matching balanced test> X<regular expression, matching balanced test> Historically, Perl regular expressions were not capable of matching balanced text. As of more recent versions of perl including 5.6.1 experimental features have been added that make it possible to do this. Look at the documentation for the (??{ }) construct in recent perlre manual pages to see an example of matching balanced parentheses. Be sure to take special notice of the warnings present in the manual before making use of this feature. CPAN contains many modules that can be useful for matching text depending on the context. Damian Conway provides some useful patterns in Regexp::Common. The module Text::Balanced provides a general solution to this problem. One of the common applications of balanced text matching is working with XML and HTML. There are many modules available that support these needs. Two examples are HTML::Parser and XML::Parser. There are many others. An elaborate subroutine (for 7-bit ASCII only) to pull out balanced and possibly nested single chars, like C<`> and C<'>, C<{> and C<}>, or C<(> and C<)> can be found in http://www.cpan.org/authors/id/TOMC/scripts/pull_quotes.gz . The C::Scan module from CPAN also contains such subs for internal use, but they are undocumented. }}}}}}}}}}}}} > > >> We keep being bothered by people who try to process HTML >> and/or XML using regexes on Freenode's #perl, and it should be in the >> FAQ: > > The answer would be "Use a module". Maybe the question should be "How > do I do X in Perl", although the answer would be really short. :) > OK. Regards, Shlomi Fish