* regexp question: match anything but not a group? @ 2014-04-01 21:30 Thorsten Jolitz 2014-04-01 23:24 ` Pascal J. Bourguignon ` (3 more replies) 0 siblings, 4 replies; 22+ messages in thread From: Thorsten Jolitz @ 2014-04-01 21:30 UTC (permalink / raw) To: help-gnu-emacs Hi List, how can I write a regexp that acts like e.g. ,------ | ".*?" `------ but does not match a group like e.g. ,--------------------- | (regexp-quote "\\)") `--------------------- ? This works more or less but does not seem to be very robust ,--------- | "[^)]*?" `--------- since ')' could appear in other contexts than the group. How can I negate a specific group of characters and not only any occurence of single characters? -- cheers, Thorsten ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-01 21:30 regexp question: match anything but not a group? Thorsten Jolitz @ 2014-04-01 23:24 ` Pascal J. Bourguignon 2014-04-03 19:48 ` Thorsten Jolitz [not found] ` <mailman.18864.1396554426.10748.help-gnu-emacs@gnu.org> 2014-04-02 5:55 ` Andreas Röhler ` (2 subsequent siblings) 3 siblings, 2 replies; 22+ messages in thread From: Pascal J. Bourguignon @ 2014-04-01 23:24 UTC (permalink / raw) To: help-gnu-emacs Thorsten Jolitz <tjolitz@gmail.com> writes: > Hi List, > > how can I write a regexp that acts like e.g. > > ,------ > | ".*?" > `------ > > but does not match a group like e.g. > > ,--------------------- > | (regexp-quote "\\)") > `--------------------- > > ? > > This works more or less but does not seem to be very robust > > ,--------- > | "[^)]*?" > `--------- > > since ')' could appear in other contexts than the group. How can I > negate a specific group of characters and not only any occurence of > single characters? (defun pjb-rx-not-string (string) (case (length string) ((0) `(* anything)) ((1) `(not (any ,string))) (otherwise `(or (not (any ,(subseq string 0 1))) (seq ,(subseq string 0 1) ,(pjb-rx-not-string (subseq string 1))))))) (defun pjb-regexp-not-string (string) (let ((all (coerce (delete-duplicates (sort (coerce string 'list) (function <))) 'string))) (rx-to-string `(seq bot (* (not (any ,string))) ,(pjb-rx-not-string string) (* (not (any ,string))) eot)))) (pjb-regexp-not-string "\\)") --> "\\(?:\\`[^)\\]*\\(?:[^\\]\\|\\\\[^)]\\)[^)\\]*\\'\\)" -- __Pascal Bourguignon__ http://www.informatimago.com/ "Le mercure monte ? C'est le moment d'acheter !" ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-01 23:24 ` Pascal J. Bourguignon @ 2014-04-03 19:48 ` Thorsten Jolitz [not found] ` <mailman.18864.1396554426.10748.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 22+ messages in thread From: Thorsten Jolitz @ 2014-04-03 19:48 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > Thorsten Jolitz <tjolitz@gmail.com> writes: > >> Hi List, >> >> how can I write a regexp that acts like e.g. >> >> ,------ >> | ".*?" >> `------ >> >> but does not match a group like e.g. >> >> ,--------------------- >> | (regexp-quote "\\)") >> `--------------------- >> >> ? >> >> This works more or less but does not seem to be very robust >> >> ,--------- >> | "[^)]*?" >> `--------- >> >> since ')' could appear in other contexts than the group. How can I >> negate a specific group of characters and not only any occurence of >> single characters? > > (defun pjb-rx-not-string (string) > (case (length string) > ((0) `(* anything)) > ((1) `(not (any ,string))) > (otherwise `(or (not (any ,(subseq string 0 1))) > (seq ,(subseq string 0 1) > ,(pjb-rx-not-string (subseq string 1))))))) > > > (defun pjb-regexp-not-string (string) > (let ((all (coerce (delete-duplicates > (sort (coerce string 'list) (function <))) 'string))) > (rx-to-string `(seq bot > (* (not (any ,string))) > ,(pjb-rx-not-string string) > (* (not (any ,string))) > eot)))) > > (pjb-regexp-not-string "\\)") > --> "\\(?:\\`[^)\\]*\\(?:[^\\]\\|\\\\[^)]\\)[^)\\]*\\'\\)" Wow, impressive, thank you. At first sight reads like pseudo-code to me, probably more CL-style than elisp style. any, anything, otherwise ... unusual stuff, I don't even find those functions with C-h f (not even after loading cl.el and cl-extra.el). This is definitely hard to digest ... -- cheers, Thorsten ^ permalink raw reply [flat|nested] 22+ messages in thread
[parent not found: <mailman.18864.1396554426.10748.help-gnu-emacs@gnu.org>]
* Re: regexp question: match anything but not a group? [not found] ` <mailman.18864.1396554426.10748.help-gnu-emacs@gnu.org> @ 2014-04-03 20:24 ` Pascal J. Bourguignon 2014-04-03 21:36 ` Thorsten Jolitz 0 siblings, 1 reply; 22+ messages in thread From: Pascal J. Bourguignon @ 2014-04-03 20:24 UTC (permalink / raw) To: help-gnu-emacs Thorsten Jolitz <tjolitz@gmail.com> writes: > "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > >> Thorsten Jolitz <tjolitz@gmail.com> writes: >> >>> Hi List, >>> >>> how can I write a regexp that acts like e.g. >>> >>> ,------ >>> | ".*?" >>> `------ >>> >>> but does not match a group like e.g. >>> >>> ,--------------------- >>> | (regexp-quote "\\)") >>> `--------------------- >>> >>> ? >>> >>> This works more or less but does not seem to be very robust >>> >>> ,--------- >>> | "[^)]*?" >>> `--------- >>> >>> since ')' could appear in other contexts than the group. How can I >>> negate a specific group of characters and not only any occurence of >>> single characters? >> >> (defun pjb-rx-not-string (string) >> (case (length string) >> ((0) `(* anything)) >> ((1) `(not (any ,string))) >> (otherwise `(or (not (any ,(subseq string 0 1))) >> (seq ,(subseq string 0 1) >> ,(pjb-rx-not-string (subseq string 1))))))) >> >> >> (defun pjb-regexp-not-string (string) >> (let ((all (coerce (delete-duplicates >> (sort (coerce string 'list) (function <))) 'string))) >> (rx-to-string `(seq bot >> (* (not (any ,string))) >> ,(pjb-rx-not-string string) >> (* (not (any ,string))) >> eot)))) >> >> (pjb-regexp-not-string "\\)") >> --> "\\(?:\\`[^)\\]*\\(?:[^\\]\\|\\\\[^)]\\)[^)\\]*\\'\\)" > > Wow, impressive, thank you. > > At first sight reads like pseudo-code to me, probably more CL-style than > elisp style. > > any, anything, otherwise ... unusual stuff, I don't even find those > functions with C-h f (not even after loading cl.el and cl-extra.el). > > This is definitely hard to digest ... rx is a famous emacs lisp library. (require 'rx) case is in (require 'cl) which should be in everybody's ~/.emacs The rest is DATA! all wasn't used, it's for a little optimization: (defun pjb-regexp-not-string (string) (let ((chars (coerce (delete-duplicates (sort (coerce string 'list) (function <))) 'string))) (rx-to-string `(seq bot (* (not (any ,chars))) ,(pjb-rx-not-string string) (* (not (any ,chars))) eot)))) -- __Pascal Bourguignon__ http://www.informatimago.com/ "Le mercure monte ? C'est le moment d'acheter !" ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-03 20:24 ` Pascal J. Bourguignon @ 2014-04-03 21:36 ` Thorsten Jolitz 0 siblings, 0 replies; 22+ messages in thread From: Thorsten Jolitz @ 2014-04-03 21:36 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > Thorsten Jolitz <tjolitz@gmail.com> writes: > >> "Pascal J. Bourguignon" <pjb@informatimago.com> writes: >> >>> Thorsten Jolitz <tjolitz@gmail.com> writes: >>> >>>> Hi List, >>>> >>>> how can I write a regexp that acts like e.g. >>>> >>>> ,------ >>>> | ".*?" >>>> `------ >>>> >>>> but does not match a group like e.g. >>>> >>>> ,--------------------- >>>> | (regexp-quote "\\)") >>>> `--------------------- >>>> >>>> ? >>>> >>>> This works more or less but does not seem to be very robust >>>> >>>> ,--------- >>>> | "[^)]*?" >>>> `--------- >>>> >>>> since ')' could appear in other contexts than the group. How can I >>>> negate a specific group of characters and not only any occurence of >>>> single characters? >>> >>> (defun pjb-rx-not-string (string) >>> (case (length string) >>> ((0) `(* anything)) >>> ((1) `(not (any ,string))) >>> (otherwise `(or (not (any ,(subseq string 0 1))) >>> (seq ,(subseq string 0 1) >>> ,(pjb-rx-not-string (subseq string 1))))))) >>> >>> >>> (defun pjb-regexp-not-string (string) >>> (let ((all (coerce (delete-duplicates >>> (sort (coerce string 'list) (function <))) 'string))) >>> (rx-to-string `(seq bot >>> (* (not (any ,string))) >>> ,(pjb-rx-not-string string) >>> (* (not (any ,string))) >>> eot)))) >>> >>> (pjb-regexp-not-string "\\)") >>> --> "\\(?:\\`[^)\\]*\\(?:[^\\]\\|\\\\[^)]\\)[^)\\]*\\'\\)" >> >> Wow, impressive, thank you. >> >> At first sight reads like pseudo-code to me, probably more CL-style than >> elisp style. >> >> any, anything, otherwise ... unusual stuff, I don't even find those >> functions with C-h f (not even after loading cl.el and cl-extra.el). >> >> This is definitely hard to digest ... > > rx is a famous emacs lisp library. (require 'rx) I've seen that one ... Ok, being aware of rx.el the whole thing appears less crytic. > case is in (require 'cl) which should be in everybody's ~/.emacs I know 'case from PicoLisp and really like it. If only the cl 'case would compare with equal too and not only with eql... > The rest is DATA! yes, I know, but still ... not the usual elisp you see everyday. > all wasn't used, it's for a little optimization: > > (defun pjb-regexp-not-string (string) > (let ((chars (coerce (delete-duplicates > (sort (coerce string 'list) (function <))) 'string))) > (rx-to-string `(seq bot > (* (not (any ,chars))) > ,(pjb-rx-not-string string) > (* (not (any ,chars))) > eot)))) I begin to understand ... -- cheers, Thorsten ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-01 21:30 regexp question: match anything but not a group? Thorsten Jolitz 2014-04-01 23:24 ` Pascal J. Bourguignon @ 2014-04-02 5:55 ` Andreas Röhler 2014-04-03 19:36 ` Thorsten Jolitz 2014-04-02 7:21 ` Thorsten Jolitz 2014-04-02 8:07 ` Andreas Röhler 3 siblings, 1 reply; 22+ messages in thread From: Andreas Röhler @ 2014-04-02 5:55 UTC (permalink / raw) To: help-gnu-emacs Am 01.04.2014 23:30, schrieb Thorsten Jolitz: > > Hi List, > > how can I write a regexp that acts like e.g. > > ,------ > | ".*?" > `------ > BTW looks wrong. .* might much nothing, if non-greedy it remains nothing (?) ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-02 5:55 ` Andreas Röhler @ 2014-04-03 19:36 ` Thorsten Jolitz 2014-04-03 22:19 ` Stefan Monnier 2014-04-04 6:37 ` Andreas Röhler 0 siblings, 2 replies; 22+ messages in thread From: Thorsten Jolitz @ 2014-04-03 19:36 UTC (permalink / raw) To: help-gnu-emacs Andreas Röhler <andreas.roehler@easy-emacs.de> writes: > Am 01.04.2014 23:30, schrieb Thorsten Jolitz: >> >> Hi List, >> >> how can I write a regexp that acts like e.g. >> >> ,------ >> | ".*?" >> `------ >> > > BTW looks wrong. .* might much nothing, if non-greedy it remains > nothing (?) But it still seems valid to protect against greedyness? ,--------------------------------------------------------------------- | '*?', '+?', '??' | These are "non-greedy" variants of the operators '*', '+' and '? | '. Where those operators match the largest possible substring | (consistent with matching the entire containing expression), the | non-greedy variants match the smallest possible substring | (consistent with matching the entire containing expression). | | For example, the regular expression 'c[ad]*a' when applied to | the string 'cdaaada' matches the whole string; but the regular | expression 'c[ad]*?a', applied to that same string, matches just | 'cda'. (The smallest possible match here for '[ad]*?' that | permits the whole expression to match is 'd'.) `--------------------------------------------------------------------- -- cheers, Thorsten ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-03 19:36 ` Thorsten Jolitz @ 2014-04-03 22:19 ` Stefan Monnier 2014-04-04 8:39 ` Thorsten Jolitz [not found] ` <mailman.18896.1396600696.10748.help-gnu-emacs@gnu.org> 2014-04-04 6:37 ` Andreas Röhler 1 sibling, 2 replies; 22+ messages in thread From: Stefan Monnier @ 2014-04-03 22:19 UTC (permalink / raw) To: help-gnu-emacs > But it still seems valid to protect against greedyness? ^^^^^^^^^^ AKA greed, Stefan ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-03 22:19 ` Stefan Monnier @ 2014-04-04 8:39 ` Thorsten Jolitz [not found] ` <mailman.18896.1396600696.10748.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 22+ messages in thread From: Thorsten Jolitz @ 2014-04-04 8:39 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: >> But it still seems valid to protect against greedyness? > ^^^^^^^^^^ > AKA greed, I just made it up, but funny enough - it does actually exist (with slightly different spelling)! From http://www.collinsdictionary.com/dictionary/english/greediness: ,------------------------------------------------------------------- | greediness (ˈɡriːdɪnɪs) | | Definitions | | noun | | 1. the quality of being greedy | | greedy (ˈɡriːdɪ Pronunciation for greedy ) | | Definitions | | adjective | | Word forms: greedier, greediest | | 1. excessively desirous of food or wealth, esp in large amounts; | voracious | 2. (postpositive) foll by for eager (for) ⇒ `a man greedy for | success' | | Derived Forms | | ˈgreedily adverb | ˈgreediness noun | | Word Origin | | Old English grǣdig; related to Old Norse grāthugr, Gothic grēdags | hungry, Old High German grātac | | Example Sentences Including 'greediness' | | At times his greediness got the better of him but he never let | his enthusiasm go off the boil. | | Sun, News of the World (2004) | | Broilers consume lots more feed-there's a good chance that | greediness has been inadvertently selected for. | | New Scientist (1998) | | Mr Carman asked him if he had a `streak of greediness " in him | for money, expensive cars and Rolex watches. | | Sun, News of the World (1999) | | Thus individuals who do experience strong pulls of greediness | often go to desperate measures to hide their behaviour. | | Knowles, Jane Know Your Own Mind `------------------------------------------------------------------- -- cheers, Thorsten ^ permalink raw reply [flat|nested] 22+ messages in thread
[parent not found: <mailman.18896.1396600696.10748.help-gnu-emacs@gnu.org>]
* Re: regexp question: match anything but not a group? [not found] ` <mailman.18896.1396600696.10748.help-gnu-emacs@gnu.org> @ 2014-04-04 9:04 ` Loris Bennett 2014-04-04 9:37 ` Andreas Röhler 2014-04-04 10:40 ` Thorsten Jolitz 0 siblings, 2 replies; 22+ messages in thread From: Loris Bennett @ 2014-04-04 9:04 UTC (permalink / raw) To: help-gnu-emacs Thorsten Jolitz <tjolitz@gmail.com> writes: > Stefan Monnier <monnier@iro.umontreal.ca> writes: > >>> But it still seems valid to protect against greedyness? >> ^^^^^^^^^^ >> AKA greed, > > I just made it up, but funny enough - it does actually exist (with > slightly different spelling)! > >>From http://www.collinsdictionary.com/dictionary/english/greediness: > > ,------------------------------------------------------------------- > | greediness (ˈɡriːdɪnɪs) > | > | Definitions > | > | noun > | > | 1. the quality of being greedy > | > | greedy (ˈɡriːdɪ Pronunciation for greedy ) > | > | Definitions > | > | adjective > | > | Word forms: greedier, greediest > | > | 1. excessively desirous of food or wealth, esp in large amounts; > | voracious > | 2. (postpositive) foll by for eager (for) ⇒ `a man greedy for > | success' > | > | Derived Forms > | > | ˈgreedily adverb > | ˈgreediness noun > | > | Word Origin > | > | Old English grǣdig; related to Old Norse grāthugr, Gothic grēdags > | hungry, Old High German grātac > | > | Example Sentences Including 'greediness' > | > | At times his greediness got the better of him but he never let > | his enthusiasm go off the boil. > | > | Sun, News of the World (2004) > | > | Broilers consume lots more feed-there's a good chance that > | greediness has been inadvertently selected for. > | > | New Scientist (1998) > | > | Mr Carman asked him if he had a `streak of greediness " in him > | for money, expensive cars and Rolex watches. > | > | Sun, News of the World (1999) > | > | Thus individuals who do experience strong pulls of greediness > | often go to desperate measures to hide their behaviour. > | > | Knowles, Jane Know Your Own Mind > `------------------------------------------------------------------- If I were you, Thorsten, I wouldn't rely on "The Sun and "NOTW" for particularly nuanced usage of the English language, even if Collins does quote them. "New Scientist" is in a different category, but I think "greed" would be much better in the example given for the following reason: I would say that "greed" is traditionally "a deadly sin", i.e. a moral failing, whereas "greediness" is a (normally) non-fatal display of overindulgence. Bankers may be reviled for their greed, but sticky-faced children told off for their greediness. In "Mastering Regular Expressions", Friedl refers to the "greediness" aspect of regular expressions, which, given the lack of a moral context, seems to me the appropriate choice. Cheers, Loris -- This signature is currently under construction. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-04 9:04 ` Loris Bennett @ 2014-04-04 9:37 ` Andreas Röhler 2014-04-04 10:40 ` Thorsten Jolitz 1 sibling, 0 replies; 22+ messages in thread From: Andreas Röhler @ 2014-04-04 9:37 UTC (permalink / raw) To: help-gnu-emacs Am 04.04.2014 11:04, schrieb Loris Bennett: > Thorsten Jolitz <tjolitz@gmail.com> writes: > >> Stefan Monnier <monnier@iro.umontreal.ca> writes: >> >>>> But it still seems valid to protect against greedyness? >>> ^^^^^^^^^^ >>> AKA greed, >> >> I just made it up, but funny enough - it does actually exist (with >> slightly different spelling)! >> >> >From http://www.collinsdictionary.com/dictionary/english/greediness: >> >> ,------------------------------------------------------------------- >> | greediness (ˈɡriːdɪnɪs) >> | >> | Definitions >> | >> | noun >> | >> | 1. the quality of being greedy >> | >> | greedy (ˈɡriːdɪ Pronunciation for greedy ) >> | >> | Definitions >> | >> | adjective >> | >> | Word forms: greedier, greediest >> | >> | 1. excessively desirous of food or wealth, esp in large amounts; >> | voracious >> | 2. (postpositive) foll by for eager (for) ⇒ `a man greedy for >> | success' >> | >> | Derived Forms >> | >> | ˈgreedily adverb >> | ˈgreediness noun >> | >> | Word Origin >> | >> | Old English grǣdig; related to Old Norse grāthugr, Gothic grēdags >> | hungry, Old High German grātac >> | >> | Example Sentences Including 'greediness' >> | >> | At times his greediness got the better of him but he never let >> | his enthusiasm go off the boil. >> | >> | Sun, News of the World (2004) >> | >> | Broilers consume lots more feed-there's a good chance that >> | greediness has been inadvertently selected for. >> | >> | New Scientist (1998) >> | >> | Mr Carman asked him if he had a `streak of greediness " in him >> | for money, expensive cars and Rolex watches. >> | >> | Sun, News of the World (1999) >> | >> | Thus individuals who do experience strong pulls of greediness >> | often go to desperate measures to hide their behaviour. >> | >> | Knowles, Jane Know Your Own Mind >> `------------------------------------------------------------------- > > If I were you, Thorsten, I wouldn't rely on "The Sun and "NOTW" for > particularly nuanced usage of the English language, even if Collins does > quote them. "New Scientist" is in a different category, but I think > "greed" would be much better in the example given for the following > reason: > > I would say that "greed" is traditionally "a deadly sin", i.e. a moral > failing, whereas "greediness" is a (normally) non-fatal display of > overindulgence. Bankers may be reviled for their greed, but > sticky-faced children told off for their greediness. > > In "Mastering Regular Expressions", Friedl refers to the "greediness" > aspect of regular expressions, which, given the lack of a moral context, > seems to me the appropriate choice. > > Cheers, > > Loris > "greediness" sounds a little bit wrapped, sorted, objective - while "greed" evokes the living beast. :) ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-04 9:04 ` Loris Bennett 2014-04-04 9:37 ` Andreas Röhler @ 2014-04-04 10:40 ` Thorsten Jolitz 2014-04-04 14:11 ` Andreas Röhler 1 sibling, 1 reply; 22+ messages in thread From: Thorsten Jolitz @ 2014-04-04 10:40 UTC (permalink / raw) To: help-gnu-emacs "Loris Bennett" <loris.bennett@fu-berlin.de> writes: > Thorsten Jolitz <tjolitz@gmail.com> writes: > >> Stefan Monnier <monnier@iro.umontreal.ca> writes: >> >>>> But it still seems valid to protect against greedyness? >>> ^^^^^^^^^^ >>> AKA greed, >> >> I just made it up, but funny enough - it does actually exist (with >> slightly different spelling)! >> >>>From http://www.collinsdictionary.com/dictionary/english/greediness: >> >> ,------------------------------------------------------------------- >> | greediness (ˈɡriːdɪnɪs) >> | >> | Definitions >> | >> | noun >> | >> | 1. the quality of being greedy >> | >> | greedy (ˈɡriːdɪ Pronunciation for greedy ) >> | >> | Definitions >> | >> | adjective >> | >> | Word forms: greedier, greediest >> | >> | 1. excessively desirous of food or wealth, esp in large amounts; >> | voracious >> | 2. (postpositive) foll by for eager (for) ⇒ `a man greedy for >> | success' >> | >> | Derived Forms >> | >> | ˈgreedily adverb >> | ˈgreediness noun >> | >> | Word Origin >> | >> | Old English grǣdig; related to Old Norse grāthugr, Gothic grēdags >> | hungry, Old High German grātac >> | >> | Example Sentences Including 'greediness' >> | >> | At times his greediness got the better of him but he never let >> | his enthusiasm go off the boil. >> | >> | Sun, News of the World (2004) >> | >> | Broilers consume lots more feed-there's a good chance that >> | greediness has been inadvertently selected for. >> | >> | New Scientist (1998) >> | >> | Mr Carman asked him if he had a `streak of greediness " in him >> | for money, expensive cars and Rolex watches. >> | >> | Sun, News of the World (1999) >> | >> | Thus individuals who do experience strong pulls of greediness >> | often go to desperate measures to hide their behaviour. >> | >> | Knowles, Jane Know Your Own Mind >> `------------------------------------------------------------------- > > If I were you, Thorsten, I wouldn't rely on "The Sun and "NOTW" for > particularly nuanced usage of the English language, even if Collins does > quote them. "New Scientist" is in a different category, but I think > "greed" would be much better in the example given for the following > reason: > > I would say that "greed" is traditionally "a deadly sin", i.e. a moral > failing, whereas "greediness" is a (normally) non-fatal display of > overindulgence. Bankers may be reviled for their greed, but > sticky-faced children told off for their greediness. > > In "Mastering Regular Expressions", Friedl refers to the "greediness" > aspect of regular expressions, which, given the lack of a moral context, > seems to me the appropriate choice. At least nuanced usage of the English language is still a topic. Here in Germany we are almost back to Martin Luthers free-style phonetic spelling after decades of so called 'language reforms' ;) -- cheers, Thorsten ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-04 10:40 ` Thorsten Jolitz @ 2014-04-04 14:11 ` Andreas Röhler 0 siblings, 0 replies; 22+ messages in thread From: Andreas Röhler @ 2014-04-04 14:11 UTC (permalink / raw) To: help-gnu-emacs Am 04.04.2014 12:40, schrieb Thorsten Jolitz: > At least nuanced usage of the English language is still a topic. Here in > Germany we are almost back to Martin Luthers free-style phonetic > spelling after decades of so called 'language reforms' ;) > I'm afraid we are fallen behind of 2000 years cultural development, before the ancient Greeks and Jesus Christ. And not just in Germany, the whole so-called western world. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-03 19:36 ` Thorsten Jolitz 2014-04-03 22:19 ` Stefan Monnier @ 2014-04-04 6:37 ` Andreas Röhler 2014-04-04 8:53 ` Thorsten Jolitz 1 sibling, 1 reply; 22+ messages in thread From: Andreas Röhler @ 2014-04-04 6:37 UTC (permalink / raw) To: help-gnu-emacs Am 03.04.2014 21:36, schrieb Thorsten Jolitz: > Andreas Röhler <andreas.roehler@easy-emacs.de> writes: > >> Am 01.04.2014 23:30, schrieb Thorsten Jolitz: >>> >>> Hi List, >>> >>> how can I write a regexp that acts like e.g. >>> >>> ,------ >>> | ".*?" >>> `------ >>> >> >> BTW looks wrong. .* might much nothing, if non-greedy it remains >> nothing (?) > > But it still seems valid to protect against greedyness? > Coming upon evaluating this, cursor at start of "asdf": (progn (looking-at ".*")(message (match-string-no-properties 0)))asdf ==> asdf (progn (looking-at ".*?")(message (match-string-no-properties 0)))asdf ==> "" ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-04 6:37 ` Andreas Röhler @ 2014-04-04 8:53 ` Thorsten Jolitz 0 siblings, 0 replies; 22+ messages in thread From: Thorsten Jolitz @ 2014-04-04 8:53 UTC (permalink / raw) To: help-gnu-emacs Andreas Röhler <andreas.roehler@easy-emacs.de> writes: > Am 03.04.2014 21:36, schrieb Thorsten Jolitz: >> Andreas Röhler <andreas.roehler@easy-emacs.de> writes: >> >>> Am 01.04.2014 23:30, schrieb Thorsten Jolitz: >>>> >>>> Hi List, >>>> >>>> how can I write a regexp that acts like e.g. >>>> >>>> ,------ >>>> | ".*?" >>>> `------ >>>> >>> >>> BTW looks wrong. .* might much nothing, if non-greedy it remains >>> nothing (?) >> >> But it still seems valid to protect against greedyness? >> > > Coming upon evaluating this, cursor at start of "asdf": > > (progn (looking-at ".*")(message (match-string-no-properties 0)))asdf > > ==> asdf > > (progn (looking-at ".*?")(message (match-string-no-properties 0)))asdf > > ==> "" Yes, it seems you are right ... so this is actually always wrong? Thanks for the tip ... -- cheers, Thorsten ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-01 21:30 regexp question: match anything but not a group? Thorsten Jolitz 2014-04-01 23:24 ` Pascal J. Bourguignon 2014-04-02 5:55 ` Andreas Röhler @ 2014-04-02 7:21 ` Thorsten Jolitz 2014-04-02 8:07 ` Andreas Röhler 3 siblings, 0 replies; 22+ messages in thread From: Thorsten Jolitz @ 2014-04-02 7:21 UTC (permalink / raw) To: help-gnu-emacs Thorsten Jolitz <tjolitz@gmail.com> writes: > Hi List, > > how can I write a regexp that acts like e.g. > > ,------ > | ".*?" > `------ > > but does not match a group like e.g. > > ,--------------------- > | (regexp-quote "\\)") > `--------------------- > > ? > > This works more or less but does not seem to be very robust > > ,--------- > | "[^)]*?" > `--------- > > since ')' could appear in other contexts than the group. How can I > negate a specific group of characters and not only any occurence of > single characters? I figured that I actually need something even smarter, because what I really want is a regexp A that matches a given other regexp B if it is a regexp-group, or not otherwise. The best version of that regexp A I can come up with right now is something like this: #+begin_src emacs-lisp (concat "^" ; BOL (regexp-quote "\\(") ; group begins "\\(\\?[[:digit:]]*:\\)?" ; shy or explicitly numbered group? "[^\\000]+?" ; any char, idea copied from org-mode (regexp-quote "\\)") ; group ends "[*+]?[?]?" ; quantifier "$") ; EOL #+end_src The problem is that in the content part ,------------------------------------------------------------------ | "[^\\000]+?" ; any char, idea copied from org-mode `------------------------------------------------------------------ anything can happen, and any number of opening and/or closing parents and sub-groups can appear, so I really need to determine if ,----------------------------------------- | (regexp-quote "\\)") ; group ends `----------------------------------------- closes ,------------------------------------------- | (regexp-quote "\\(") ; group begins `------------------------------------------- and thats kind of hard to do with regexp syntax. I know now that I could simulate *look-ahead-assertions* for my original problem, which aren't implemented in Emacs AFAIK, something on the line of: #+begin_src emacs-lisp (progn (and (looking-at ".*") (not (eq (char-after) ?\)) (not (eq (char-after (+ 1 (point)) MY-CHAR))) (not (eq (char-after (+ 2 (point)) MY-CHAR))) [...] )) #+end_src but counting and bookkeeping of opening and closing parens in regexp B looks too difficult to me. I can only imagine to check parens with lisp first (e.g. by using `forward-sexp' or so) and then use a regexp like above that does not care what is inside the group enclosing parens. Then I could drop this part from the regexp too ,---------------------------------------------------------------- | "\\(\\?[[:digit:]]*:\\)?" ; shy or explicitly numbered group? `---------------------------------------------------------------- because all that counts are the matching parens. Any ideas how to best check if a given regexp is a regexp group or not? -- cheers, Thorsten ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-01 21:30 regexp question: match anything but not a group? Thorsten Jolitz ` (2 preceding siblings ...) 2014-04-02 7:21 ` Thorsten Jolitz @ 2014-04-02 8:07 ` Andreas Röhler 2014-04-03 10:50 ` Thorsten Jolitz 2014-04-03 14:37 ` Stefan Monnier 3 siblings, 2 replies; 22+ messages in thread From: Andreas Röhler @ 2014-04-02 8:07 UTC (permalink / raw) To: help-gnu-emacs Am 01.04.2014 23:30, schrieb Thorsten Jolitz: > > Hi List, > > how can I write a regexp that acts like e.g. > > ,------ > | ".*?" > `------ > > but does not match a group like e.g. > > ,--------------------- > | (regexp-quote "\\)") > `--------------------- > > ? > > This works more or less but does not seem to be very robust > > ,--------- > | "[^)]*?" > `--------- > > since ')' could appear in other contexts than the group. How can I > negate a specific group of characters and not only any occurence of > single characters? > You need look-ahead-assertions, which aren't implemented in Emacs AFAIK. Here is a workaround to play with: (progn (and (looking-at ".*") (not (eq (char-after) ?\)))) (message "%s" (match-string-no-properties 0))) Test with more than one char ahead writing n char-after: (not (eq (char-after (+ 1 (point)) MY-CHAR))) (not (eq (char-after (+ 2 (point)) MY-CHAR))) ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-02 8:07 ` Andreas Röhler @ 2014-04-03 10:50 ` Thorsten Jolitz 2014-04-03 23:46 ` Bob Proulx 2014-04-03 14:37 ` Stefan Monnier 1 sibling, 1 reply; 22+ messages in thread From: Thorsten Jolitz @ 2014-04-03 10:50 UTC (permalink / raw) To: help-gnu-emacs Andreas Röhler <andreas.roehler@easy-emacs.de> writes: > Am 01.04.2014 23:30, schrieb Thorsten Jolitz: >> >> Hi List, >> >> how can I write a regexp that acts like e.g. >> >> ,------ >> | ".*?" >> `------ >> >> but does not match a group like e.g. >> >> ,--------------------- >> | (regexp-quote "\\)") >> `--------------------- >> >> ? >> >> This works more or less but does not seem to be very robust >> >> ,--------- >> | "[^)]*?" >> `--------- >> >> since ')' could appear in other contexts than the group. How can I >> negate a specific group of characters and not only any occurence of >> single characters? >> > > > You need look-ahead-assertions, which aren't implemented in Emacs AFAIK. > Here is a workaround to play with: > > (progn > (and (looking-at ".*") > (not (eq (char-after) ?\)))) > (message "%s" (match-string-no-properties 0))) > > Test with more than one char ahead writing n char-after: > > (not (eq (char-after (+ 1 (point)) MY-CHAR))) > (not (eq (char-after (+ 2 (point)) MY-CHAR))) Since gmane.org was down sometime, this thread was continued with PMs, so, just for reference, here is my solution to an extended form of the original problem (i.e. determine if a given regexp is a regexp group or not): ,------------------------------------------------------- | Andreas Röhler <andreas.roehler@easy-emacs.de> writes: | | > Which would extend the question... | > You wanted not to match any | > | > (regexp-quote "\\)") | | I think I got it: | | #+begin_src emacs-lisp | (defun tj/regexp-group-p (rgxp) | "Return RGXP if its a regexp group, nil otherwise." | (with-temp-buffer | (insert (format "%S" rgxp)) | (goto-char (point-min)) | (if (ignore-errors | (save-excursion | (and | (re-search-forward "(") | (save-match-data | (looking-back | (concat "^" (regexp-quote "\"\\\\(")) | (line-beginning-position))) | (goto-char (match-beginning 0)) | (progn | (forward-sexp) | (looking-at | "[*+]?[?]?\"$"))))) | rgxp nil))) | #+end_src | | Thanks for you help! `------------------------------------------------------- -- cheers, Thorsten ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-03 10:50 ` Thorsten Jolitz @ 2014-04-03 23:46 ` Bob Proulx 2014-04-04 8:43 ` Thorsten Jolitz 0 siblings, 1 reply; 22+ messages in thread From: Bob Proulx @ 2014-04-03 23:46 UTC (permalink / raw) To: help-gnu-emacs Thorsten Jolitz wrote: > Since gmane.org was down sometime, this thread was continued with PMs, > so, ... I realize that many people read the mailing list through the web archives, through the news interface, and so forth. But it is a mailing list! If you are going to send private mail because one of the web archives is down you could just as easily send email to the mailing list as it is intended to be used. <me wags finger/> :-) Bob ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-03 23:46 ` Bob Proulx @ 2014-04-04 8:43 ` Thorsten Jolitz 0 siblings, 0 replies; 22+ messages in thread From: Thorsten Jolitz @ 2014-04-04 8:43 UTC (permalink / raw) To: help-gnu-emacs Bob Proulx <bob@proulx.com> writes: > Thorsten Jolitz wrote: >> Since gmane.org was down sometime, this thread was continued with PMs, >> so, ... > > I realize that many people read the mailing list through the web > archives, through the news interface, and so forth. But it is a > mailing list! If you are going to send private mail because one of > the web archives is down you could just as easily send email to the > mailing list as it is intended to be used. <me wags finger/> :-) I received private mails and answered privately ... took me a while to figure out that gmane is down and these were just copies of mailing list posts. Somehow the news interface is so much nicer, and as you say, many people seem to use it. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-02 8:07 ` Andreas Röhler 2014-04-03 10:50 ` Thorsten Jolitz @ 2014-04-03 14:37 ` Stefan Monnier 2014-04-03 19:32 ` Thorsten Jolitz 1 sibling, 1 reply; 22+ messages in thread From: Stefan Monnier @ 2014-04-03 14:37 UTC (permalink / raw) To: help-gnu-emacs > You need look-ahead-assertions, which aren't implemented in Emacs AFAIK. Actually, what he needs is negation. In Perl regexp, negation is provided via look-ahead assertions, but in lex.el, they're provided as the "normal negation operator". I.e. in lex.el (negate RE) is a regular expression which matches any string not matched by RE. Stefan ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: regexp question: match anything but not a group? 2014-04-03 14:37 ` Stefan Monnier @ 2014-04-03 19:32 ` Thorsten Jolitz 0 siblings, 0 replies; 22+ messages in thread From: Thorsten Jolitz @ 2014-04-03 19:32 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: >> You need look-ahead-assertions, which aren't implemented in Emacs AFAIK. > > Actually, what he needs is negation. In Perl regexp, negation is > provided via look-ahead assertions, but in lex.el, they're provided as the > "normal negation operator". I.e. in lex.el (negate RE) is a regular > expression which matches any string not matched by RE. Very useful, thanks, I just installed lex.el. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2014-04-04 14:11 UTC | newest] Thread overview: 22+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-04-01 21:30 regexp question: match anything but not a group? Thorsten Jolitz 2014-04-01 23:24 ` Pascal J. Bourguignon 2014-04-03 19:48 ` Thorsten Jolitz [not found] ` <mailman.18864.1396554426.10748.help-gnu-emacs@gnu.org> 2014-04-03 20:24 ` Pascal J. Bourguignon 2014-04-03 21:36 ` Thorsten Jolitz 2014-04-02 5:55 ` Andreas Röhler 2014-04-03 19:36 ` Thorsten Jolitz 2014-04-03 22:19 ` Stefan Monnier 2014-04-04 8:39 ` Thorsten Jolitz [not found] ` <mailman.18896.1396600696.10748.help-gnu-emacs@gnu.org> 2014-04-04 9:04 ` Loris Bennett 2014-04-04 9:37 ` Andreas Röhler 2014-04-04 10:40 ` Thorsten Jolitz 2014-04-04 14:11 ` Andreas Röhler 2014-04-04 6:37 ` Andreas Röhler 2014-04-04 8:53 ` Thorsten Jolitz 2014-04-02 7:21 ` Thorsten Jolitz 2014-04-02 8:07 ` Andreas Röhler 2014-04-03 10:50 ` Thorsten Jolitz 2014-04-03 23:46 ` Bob Proulx 2014-04-04 8:43 ` Thorsten Jolitz 2014-04-03 14:37 ` Stefan Monnier 2014-04-03 19:32 ` Thorsten Jolitz
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.