newbie parsing question
[1/4] from: jseq:mediaone at: 3-Mar-2001 13:39
I've been wrestling unsuccessfully with the parsing dialect on the following
simple(?) problem.
I've got an <IMG SRC=""> tag, and I'd like to parse the filename in the SRC
attribute.
The format of the filename is : /some-path/AAA00000s0.jpg or
/some-path/AAA00000s00.jpg where A is a character [A-Z], and 0 represents
a digit. I want to grab the one or two digits following the 's'.
In perl, this would be something like:
$html =~ s/s([0-9]+)\.jpg/$1/
I'm having a traumatic experience mapping this to REBOL. Any suggestions?
[2/4] from: agem:crosswinds at: 4-Mar-2001 0:22
>> a: {/some-path/AAA00000s12.jpg}
== "/some-path/AAA00000s12.jpg"
>> jpg: head reverse ".jpg"
== "gpj."
>> parse head reverse a [thru jpg copy b to "s" to end]
== true
>> b: head reverse b
== "12"
rebol-parse has no backtracking like perl, sadly.
Comming from left is difficult in this case IMO.
something like
parse tail a [reverse thru ».jpg« copy b to »s« to end]
would be nice for such cases..
Volker
>>>>>>>>>>>>>>>>>> Ursprüngliche Nachricht <<<<<<<<<<<<<<<<<<
Am 03.03.01, 19:39:42, schrieb "John Sequeira" <[jseq--mediaone--net]> zum
Thema [REBOL] newbie parsing question:
[3/4] from: arolls:bigpond:au at: 4-Mar-2001 14:23
> I've got an <IMG SRC=""> tag, and I'd like to parse the filename
> in the SRC
<<quoted lines omitted: 3>>
> represents
> a digit. I want to grab the one or two digits following the 's'.
a: "/some-path/AAA00000s12.jpg"
parse a [some [thru "/"] copy filename thru ".jpg"] ; get the filename
filename ;== "AAA00000s12.jpg"
Now extend the above to parse the filename:
alpha: charset "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
digit: charset "0123456789"
parse a [some [thru "/"] copy filename thru ".jpg"
(parse filename [3 alpha 5 digit "s" copy n to "."])]
n ;== "12"
Regards,
Anton.
[4/4] from: brett:codeconscious at: 4-Mar-2001 14:59
REBOL [
Author: "Brett Handley"
Title: "Parser for special files."
Comment: "Example of parsing for John Sequeira"
]
ctx-special-file-parser: context [
desired-number: none ; Will be set by the parser.
a-char: charset [#"A" - #"Z" #"a" - #"z"] ; Parse rule to match characters.
a-digit: charset [#"0" - #"9"] ; Parse rule to match digits.
; Parse rule to match the filename structure.
; Will set the field desired-number
file-name-structure: [
(desired-number: none)
some a-char
some a-digit
#"s"
copy desired-number some a-digit
to end
]
set 'print-special-file-number func [
full-file-path [file!]
][
either parse second split-path full-file-path file-name-structure [
print desired-number
][print "parse failed"]
]
]
; Examples
print-special-file-number %/some-path/AAA00000s0.jpg
print-special-file-number %/some-path/Absdfpkj349874s12.jpg
print-special-file-number %/some-path/As0.jpg
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted