Jump to content

StringRegExp help with CRLF


Recommended Posts

I was trying to search for text within a file or output from a console and noticed the StringregExp had issues with new lines.  Like when I searched for text.*.joe  and the newline existed within the data?

So I tried a experiment

$AA = "text.*joe"    <--- This worked
MsgBox(0, "test", StringRegExp("text12testjohnjoe" & @CRLF & "dan" & @CRLF & "bob", $AA,0))

$AA = "text.*joe.*bob"    <--- This did not work

Is .* the wrong regular expression to skip unwanted data including newline?  Any suggestions?

Thanks,

Dan

Link to comment
Share on other sites

Depends.

Read the help file again for StringRegExp under "Character Types". See that . (dot) matches or not a newline sequence depending on an option. Read up what this option does and fix your own pattern.

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

Explain what the general form of the input is and what exactly you want to extract.

Because "searched for text .*joe  and the newline existed within the data" is ambiguous about whether or not you wanted newline sequences to remain within the captured "data". I took data to mean "everything meaningful".

You need mathematical-type precision when specifying what you need a regexp to do: for instance, newline sequences _are_ text.

If you want to capture something satisfying a more stringent criterion you must specify this criterion clearly.

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 didn't mean to be ambiguous, I'm new to regex so I wasn't aware whats involved with asking questions about it and how to ask.  Your first post helped me figure out what I was missing though.

A file is read or a body of text captured in a variable.  and the user inputs texts or pattern to see if the data exists within the read data in the variable. 

And if the user wanted to search for more than 1 text that could be anywhere, they can input "hello.*dan.*goodbye" to ensure those 3 words exist within the body of text.  newline was stopping the regex from working correctly, so from your advice, I figured out that adding (?s) will changed the line to dotAll and now also skips newlines when I use .*

thanks

Edited by bigdogdan2
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...