kylomas

SRER Not Returning Expected Results

8 posts in this topic

#1 ·  Posted (edited)

I'm trying to populate $title with whatever is on the line containing "#title#".

These tries are blanking out everything preceding #title# on that line and returning all other lines.

#include <array.au3>

;#title#          the title of this code

local $str = fileread(@ScriptFullPath)

;local $title = stringregexpreplace($str,'(?i).*?\#title\#(.+).*', '$1')
;local $title = stringregexpreplace($str,'(?im).*?\#title\#(.+).*', '$1')
;local $title = stringregexpreplace($str,'(?im)^.*?\#title\#(.+).*$', '$1')
;local $title = stringregexpreplace($str,'(?im)^.*?\#title\#(.+\R).*$', '$1')
local $title = stringregexpreplace($str,'(?im)\#title\#(.+)', '$1')

ConsoleWrite(@error & ' - ' & @extended & ' - ' & $title & @CRLF)

_arraydisplay($title)

exit

How can I return whatever follows #title# on that line only?

kylomas

more tries

;local $title = stringregexpreplace($str,'(?im).*?\#title\#(.+)$.*', '$1')
local $title = stringregexpreplace($str,'(?im).*?\#title\#(.+).*$', '$1')

I'm lost...

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites



local $title = stringregexp($str, '(?im)\#title\#(.+)', 1)

Aren't you making your life difficult?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Hi jchd, been awhile...

I can get SRE to return the correct results all day long, can't figure out the SRER part...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

mikell,

Thanks, that did it, now to try to understand it...

How is this

How can I return whatever follows #title# on that line only?

 

not clear?


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Please don't care, the antislashes everywhere in #title# caused me trouble  :)

N  matches anything except newline, so in (N+).* the engine stops backreferencing at the first newline encountered and .* is the whole rest of the string

Anyway jchd is right, the new array feature allows to get the expected string immediately and it's much easier

local $title = stringregexp($str, '#title#\s*(\N+)', 1)[0]

Share this post


Link to post
Share on other sites

Yea, I was going to give up and go with that except that the title may or may not appear...thanks for your help!


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

You can also cheat to get an empty capture on failure :

$title = stringregexp($str, '#title#(\N+)|()$', 1)[0])

I don't know if it's a good idea, but it works and can be useful sometimes.

Edited by jguinch

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now