Jump to content

Regex working on Regex101 not working


Recommended Posts

I have a very simple Regex which i got tested on Regex101:

 

Data:

Adres: Statenkanaal 11 1234KD Maastricht
Telefoon: 0654
Date: 1-06-1999

I want to grab a group :the line after Adres: and finish with a newline:

 

This can be done with Adres:(.*?)\n

 

I want to reproduce this in AutoIT:

#include <StringConstants.au3>
Local $sMail  =    "Adres: Statenkanaal 11 1234KD Maastricht"  & @CRLF & _
                        "Telefoon: 004999999966673"  & @CRLF & _
                        "Geboortedatum: 21-7-2001"  & @CRLF & _
                        " OrderID: 5102"  & @CRLF & _
                        ""  & @CRLF & _
                        "Datum: 20-2-2022 14:56:39"

$sMailAddress = StringRegExp($sMail, "(?i)Adres:(.*?)\n", $STR_REGEXPARRAYMATCH , 1)
MsgBox($MB_SYSTEMMODAL, "", $sMailAddress[0]) 

 

 

But this doesn't match.  Do I miss something in AutoIT regarding new lines?

Edited by Jos
added codebox and include, changed address to ensure it is invalid.
Link to comment
Share on other sites

  • Developers

These should be correct:

$sMailAddress = StringRegExp($sMail, "(?i)Adres:(.*?)\r", $STR_REGEXPARRAYMATCH,1)
; or
$sMailAddress = StringRegExp($sMail, "(?i)Adres:(.*?)[\r\n]", $STR_REGEXPARRAYMATCH,1)
; or
$sMailAddress = StringRegExp($sMail, "(?i)Adres:(.*?)\v", $STR_REGEXPARRAYMATCH,1)
; or
$sMailAddress = StringRegExp($sMail, "(?im)^Adres:(.*?)$", $STR_REGEXPARRAYMATCH,1)

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You can get along with just:

$sMailAddress = StringRegExp($sMail, "(?i)Adres:\h*(.*)", $STR_REGEXPARRAYMATCH, 1)

In PCRE dot (.) doesn't match a newline sequence. \h* ahead avoids grabbing the space.

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

3 hours ago, trekker said:

I want to reproduce this in AutoIT :

(Note from Musashi : I have replaced the data with xxxx ;))

Local $sMail  =    "Adres: XXXX Maastricht"  & @CRLF & _
                        "Telefoon: XXXXXXXXXXX"  & @CRLF & _
                        "Geboortedatum: XX-X-XXXX"  & @CRLF & _
                        " OrderID: XXXX"  & @CRLF & _
                        ""  & @CRLF & _
                        "Datum: 29-5-2022 14:56:39"

 

Off topic : In your code snippet you apparently used real personal data. I would remove these as a precaution or provide fantasy data.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

  • Developers
Just now, Musashi said:

I would remove these as a precaution or provide fantasy data.

It is already changed out of precaution! ;) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...