Re: [racket] Regexp question

2014-04-15 Thread Manfred Lotz
On Tue, 15 Apr 2014 23:09:46 -0400 "David T. Pierson" wrote: > On Tue, Apr 15, 2014 at 09:09:00PM +0200, Manfred Lotz wrote: > > -> (count-substring "[\\[]" "a[rts[a3]") > > 2 > > -> (count-substring "[a-z\\[]" "a[rts[a3]") > > 7 > > -> (count-substring "[\\]]" "a[rts[a3]") > > 0 > > > > The fir

Re: [racket] Regexp question

2014-04-15 Thread David T. Pierson
On Tue, Apr 15, 2014 at 09:09:00PM +0200, Manfred Lotz wrote: > -> (count-substring "[\\[]" "a[rts[a3]") > 2 > -> (count-substring "[a-z\\[]" "a[rts[a3]") > 7 > -> (count-substring "[\\]]" "a[rts[a3]") > 0 > > The first two seem to work fine, the last one doesn't. Those backslashes are not escapi

Re: [racket] Regexp question

2014-04-15 Thread Manfred Lotz
On Tue, 15 Apr 2014 21:39:24 +0200 Jens Axel Søgaard wrote: > If you need a literal ] you can use (regexp-quote "]") > > > (count-substring (regexp-quote "]") "a[rts[a3") > 4 > Didn't know this. It is not so bad. But I might want to match more than one character. For example the following

Re: [racket] Regexp question

2014-04-15 Thread Jens Axel Søgaard
If you need a literal ] you can use (regexp-quote "]") > (count-substring (regexp-quote "]") "a[rts[a3") 4 -- Jens Axel Søgaard 2014-04-15 21:09 GMT+02:00 Manfred Lotz : > On Rosetta code in "Count occurrences of a substring" I found this for > Racket: > > (define count-substring > (com

Re: [racket] Regexp: Ways to reduce number of list elements returned?

2013-05-13 Thread Greg Hendershott
I've taken to using `match` for this. Your example: (regexp-match #rx"\"(.*)" "a\"b") I would write as: (match "a\"b" [(regexp "\"(.*)" (list _ x)) x]) ; "b" Handling the no-match case by returning #f: (match "ab" [(regexp "\"(.*)" (list _ x)) x] [_ #f]) ; #f Laurent's approach of defin

Re: [racket] Regexp: Ways to reduce number of list elements returned?

2013-05-10 Thread Laurent
No, regexp-match is designed to return first the entire match followed by the matched parenthesized expressions. You can always write a wrapper that returns the parenthesized expressions if you want: #lang racket (define (regexp-match-sub-matches rx str) (cdr (or (regexp-match rx str) '(a . #f)

Re: [racket] Regexp-match question: ? means what, or .*? means what...

2013-05-08 Thread JP Verkamp
> > ;This I understand: > ;To return pattern and everything to left of first instance of pattern, > use: [^]* ;where ^ means 'not'; example: > (car (regexp-match* #rx"[^/]*/" "12/4/6")) ; => "12/" > A caveat for this. in the first instance isn't quite right. [...] defines a single character. [abc

Re: [racket] Regexp question: Pattern that can match everything to left of first pattern?

2013-05-08 Thread John Clements
On May 8, 2013, at 11:54 AM, Eli Barzilay wrote: > An hour ago, John Clements wrote: >> >> The traditional way to do this would be to match a sequence of >> non-x's followed by an x, like this: >> >> #lang racket >> >> (regexp-match #rx"[^x]*x" "12x4x6") ; => '("12x") >> >> Things get a bit m

Re: [racket] Regexp question: Pattern that can match everything to left of first pattern?

2013-05-08 Thread Eli Barzilay
An hour ago, John Clements wrote: > > The traditional way to do this would be to match a sequence of > non-x's followed by an x, like this: > > #lang racket > > (regexp-match #rx"[^x]*x" "12x4x6") ; => '("12x") > > Things get a bit more interesting if you put a more complex pattern > in place o

Re: [racket] Regexp question: Pattern that can match everything to left of first pattern?

2013-05-08 Thread Norman Gray
Don, hello. On 2013 May 8, at 18:25, Don Green wrote: > (regexp-match #rx"___" "12x4x6") ; => '("12x") ;returns everything to left > of first pattern x Orthogonally to John's answer (which is all about matching the thing you want), you can aim to match the pattern you want to terminate the th

Re: [racket] Regexp question: Pattern that can match everything to left of first pattern?

2013-05-08 Thread John Clements
On May 8, 2013, at 10:25 AM, Don Green wrote: > Regexp question: Is there a pattern that can match everything to left of > first pattern? > > (regexp-match #rx"x.*" "12x4x6") ; => '("x4x6") ;returns everything to right > of first pattern x > > (regexp-match #rx"___" "12x4x6") ; => '("12x") ;r

Re: [racket] regexp-match to return a line containing a specified string...

2013-05-07 Thread Danny Yoo
On Tue, May 7, 2013 at 3:08 PM, Don Green wrote: > Trying to use regexp-match to return a line containing a specified string... > > > ;Create fn: find-string.ss. > > ;Given a file and a find-string. > > ;Returns a line-string with first find. > > ;The input file has a lot of lines. In this case,

Re: [racket] regexp with \"

2012-10-22 Thread Tobias Hammer
(regexp-match #rx"c\"d" "abc\"def") and (regexp-match #rx"c\\\"d" "abc\"def") seems to work. On Mon, 22 Oct 2012 16:30:15 +0200, Nadeem Abdul Hamid wrote: When I insert \\" in the pattern, the double quote is interpreted as the end of the pattern. You have to escape the quote too...

Re: [racket] regexp with \"

2012-10-22 Thread Nadeem Abdul Hamid
> > When I insert \\" in the pattern, the double quote is interpreted as the > end of the pattern. > You have to escape the quote too... " ... \\\" ... " --- nadeem Racket Users list: http://lists.racket-lang.org/users

Re: [racket] Regexp character classes

2011-08-27 Thread gabor papp
On 8/27/11 10:04 AM, Neil Van Dyke wrote: #lang racket/base (define str "17.4 25.4 15.7 13.7 19.4 20.9 ") (regexp-split #rx"[ \t]+" str) or with posix character class: (regexp-split #px"[[:space:]]+" str) _ For list-related administrative tasks:

Re: [racket] Regexp character classes

2011-08-27 Thread Neil Van Dyke
I don't know about ":space:", but you can do regexp character classes the old-fashioned way: #lang racket/base (define str "17.4 25.4 15.7 13.7 19.4 20.9 ") (regexp-split #rx"[ \t]+" str) ;;==> '("17.4" "25.4" "15.7" "13.7" "19.4" "20.9" "") I also used "regexp" instead

Re: [racket] regexp-match number

2011-06-22 Thread Matthew Flatt
You could wrap the "\1" with the grouping operator "(?:...)": > (regexp-match #px"(.*)\\1001" "abcabc001") bad pregexp string: backreference number is larger than the highest-numbered cluster > (regexp-match #px"(.*)(?:\\1)001" "abcabc001") '("abcabc001" "abc") At Wed, 22 Jun 2011 09:52:09

Re: [racket] regexp-match-evt and file-position

2011-06-16 Thread Matthew Flatt
The `port-commit-peeked' function (used by `regexp-match-evt') was deeply broken with respect to `file-position' and `port-next-location'. I see no workaround for old versions, but the problem is now fixed in the current development version (in the git repo). At Sat, 11 Jun 2011 07:19:03 -0700, Ma

Re: [racket] regexp-match-evt and file-position

2011-06-11 Thread Matthew Flatt
Thanks for the report! I think the bug is more specifically in the implementation of `port-commit-peeked' for some kinds of ports, since the following program also has the wrong result: #lang racket/base (define-values (in out) (make-pipe)) (display "12345" out) (peek-bytes 3 0 in) (port-com

Re: [racket] regexp

2011-02-12 Thread Noel Welsh
You can use the primitive require, which is #%require IIRC. HTH, N. On Sat, Feb 12, 2011 at 1:34 AM, geb a wrote: > How do I use regexp with r5rs?  I had some difficulty using outside of racket. > > Sincerely, > Dan > > > > _ >  For list-related ad

Re: [racket] regexp operations on character input ports returning bytes

2010-12-25 Thread Matthew Flatt
At Sat, 25 Dec 2010 10:23:54 -0500, Neil Van Dyke wrote: > When doing a regexp on a character input port, what's the best way to > get string results out instead of bytes results? Decode the results of `regexp-match' using `bytes->string/utf-8'. > For example, this is documented behavior, but no

Re: [racket] regexp-match* that returns clusters?

2010-12-19 Thread Eli Barzilay
Yesterday, Todd O'Bryan wrote: > Is there some equivalent of regexp-match* that returns a list of all > the (non-overlapping) matches in a string. > > I want something like: > > > (regexp-match*-clusters #px"(?:^|\\s+)([A-Z])" "This gets Initial CAPS, I > > hope") > '(("T" "T") (" I" "I") (" C"

Re: [racket] regexp-match* that returns clusters?

2010-12-19 Thread Todd O'Bryan
I wrote the following function (define/contract (regexp-match-all re str) (regexp? string? . -> . (listof (listof (or/c string? #f (map (λ (s) (regexp-match re s)) (regexp-match* re str))) I don't know if it would be worth including among the standard regexp operators. Todd On Sa

Re: [racket] regexp-replace* with input-port ==> Re: multi-replace function

2010-12-07 Thread Eli Barzilay
15 minutes ago, YC wrote: > On Tue, Dec 7, 2010 at 12:25 AM, Eli Barzilay wrote: > > > > Actually, there's a problem -- there is already an optional > > argument for the prefix, and if an output port is added, it should > > be added before that for consistency but that will be > > incompatible. >

Re: [racket] regexp-replace* with input-port ==> Re: multi-replace function

2010-12-07 Thread YC
On Tue, Dec 7, 2010 at 12:25 AM, Eli Barzilay wrote: > > Actually, there's a problem -- there is already an optional argument > for the prefix, and if an output port is added, it should be added > before that for consistency but that will be incompatible. That's unfortunate. Looking at v4.2.5 I

Re: [racket] regexp-replace* with input-port ==> Re: multi-replace function

2010-12-07 Thread Eli Barzilay
10 minutes ago, YC wrote: > On Mon, Dec 6, 2010 at 11:49 PM, Eli Barzilay wrote: > > > Well, that would be an obvious issue... It might be possible to > > do this if they're extended to get an output port too, something > > like: > > > > (regexp-replace* #rx"foo" inp "bar" outp) > > > > doing t

Re: [racket] regexp-replace* with input-port ==> Re: multi-replace function

2010-12-07 Thread YC
On Mon, Dec 6, 2010 at 11:49 PM, Eli Barzilay wrote: > > Well, that would be an obvious issue... It might be possible to do > this if they're extended to get an output port too, something like: > > (regexp-replace* #rx"foo" inp "bar" outp) > > doing the same thing as the loop that I wrote. So

Re: [racket] regexp-replace* allows no sub-expressions?

2010-06-26 Thread Matthew Flatt
The change was not intentional, and I'll fix it soon. Thanks for the report! At Sat, 26 Jun 2010 15:38:49 -0700, synx wrote: > > Okay what. I've long relied on the behavior of regexp-replace* to single > out a number of substrings within a big string, and let me mangle those > substrings in a pr