Page 1 of 1

Need some help I don't quite get all this dot stuff

Posted: 2010-07-18 00:53:41
by loulesko
I'm trying to extract the chapter number from the text "Chapter 3" which is a previous find from the cursor position. I'm trying to use the following

$sels = $doc.text.find '(?<=Chapter )[[:digit:]](?=\\n)', 'Er-Wr', '-am'

How do I get the number three from $sels it just gives me ranges. I'm not quite hip to this type of coding any help and education appreciated.

thanks
Lou

Re: Need some help I don't quite get all this dot stuff

Posted: 2010-07-18 01:44:57
by Kino
loulesko wrote:I'm trying to extract the chapter number from the text "Chapter 3" which is a previous find from the cursor position. I'm trying to use the following

$sels = $doc.text.find '(?<=Chapter )[[:digit:]](?=\\n)', 'Er-Wr', '-am'

How do I get the number three from $sels it just gives me ranges.
You can get the number by $n = $sels.subtext or $n = $sels.substring but find command does not know where the cursor is positioned and, with r option, always searches from the end of the document. Try the following instead:

Code: Select all

Find '(?<=Chapter )[[:digit:]]+(?=\n)', 'Er-W', '-am'
$n = Read Selection
Prompt $n
And if you want to verify if the number has been found successfully . . .

Code: Select all

$i = Find '(?<=Chapter )[[:digit:]]+(?=\n)', 'Er-W', '-am'
if $i
	$n = Read Selection
	Prompt $n
else
	Prompt 'Chapter number not found'
end
• I added + (one or more times) after [[:digit:]] because your document may have more than nine chapters.
• You don’t need putting two \ before n although Macroize does.

Re: Need some help I don't quite get all this dot stuff

Posted: 2010-07-19 17:20:35
by loulesko
Kino,

Amazing. Thank you again for all your help.

best
Lou