Jump to content

StringRegExp or ???


Recommended Posts

I continually receive the message:

Subscript used with non-Array variable.:

I do not know if this is related to StringRegExp or arrays, or both. Code is:

$asResult = StringRegExp($line, '((?i)[:alpha](1,25))', 1)

MsgBox(0, "Line Reads", $asResult[0])

The $line is a one line text string that starts with a bunch of 'junk' such as --99 48/56 and then gets to the part that I want which is alpha until the very end which always ends with 2-5 numbers.

Ideally I would like to capture from the start of the text - ignoring the junk - all the way to the end of the line.

unfortunately I continually get the error message mentioned above. Anyone know what I am doing wrong?

Link to comment
Share on other sites

Just test for @error after StringRegExp() and don't try to use the returned array unless @error = 0:

$sLine = ""
$sPatt = '((?i)[:alpha](1,25))' ; Fix your pattern here
$asResult = StringRegExp($line, $sPatt, 1)
If @error Then
    MsgBox(16, "Error", "Error on RegExp; @error = " & @error & "; @extended = " & @extended)
Else
    MsgBox(0, "Line Reads", $asResult[0])
EndIf

Your pattern is still wrong, but you have the error handling now.

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

More than likely you have a bad expression. Anytime you are working with arrays you need to validate the data you receive for errors.

$asResult = StringRegExp($line, '((?i)[:alpha](1,25))', 1)
If @error Then
  MsgBox(0, "Line Reads", $asResult[0])
Else
  MsgBox(0, "Line Reads", "Error: No matches.")
EndIf

Edit: @PsaltyDS beat me to it.

Edited by zorphnog
Link to comment
Share on other sites

Some samples of data to match would have been a must. Guesswork: "(?i)^[^a-z]*([a-z](?:\w|\s)*\d{2,5})$"

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)

Link to comment
Share on other sites

"(?i).+([a-z]+\d{2,5}$"

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I was about posting the same, but finally thought the "all text"part could well contain embedded digits, like below, so I added the extra guard.

-- 46 148906/246514896 Exception 17 occured at flight second 1645

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)

Link to comment
Share on other sites

I was about posting the same, but finally thought the "all text"part could well contain embedded digits, like below, so I added the extra guard.

-- 46 148906/246514896 Exception 17 occured at flight second 1645

Yours will work just fine. If the "all text" was going to include digits then I would have used either \w+ or [a-z0-9].

The only reason I posted at all is, just the other day I was posting on my blog about the fact REGEX is great for solving complex problems but then we turn around and make the SRE too complex, or at least more complex than is usually required for the task at hand. I shouldn't make them that simple in the forums because we know that people seldom give us true examples of what they are starting with and what they expect returned.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

True and many scripters with little experience see the need for precision and rigor as something which doesn't apply to their "simple" case. Unfortunately (or perhaps fortunately) their computers behave the same way as ours and deliver the same garbage as ours when directed by faulty logic or inconsistent rules. Today's PC simply do that faster.

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)

Link to comment
Share on other sites

True and many scripters with little experience see the need for precision and rigor as something which doesn't apply to their "simple" case. Unfortunately (or perhaps fortunately) their computers behave the same way as ours and deliver the same garbage as ours when directed by faulty logic or inconsistent rules. Today's PC simply do that faster.

Isn't it amazing what people can class as simple when they are asking for help though? It can range from the truly simple to something that needs a super computer to do the calculations.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Fortunately we have a super language at our disposal, an incredibly wide-spectrum library, a huge cumulated culture and experience and above all ... big & brave hearts!

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)

Link to comment
Share on other sites

Fortunately we have a super language at our disposal, an incredibly wide-spectrum library, a huge cumulated culture and experience and above all ... big & brave hearts!

You left out the "all mixed together with a pinch of stupidity."

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...