Jump to content

RegExp Help ^_^


Recommended Posts

Hello guys ;)

I have a script to update and i am still a bit lost with regexp. Particulary when I have a big patterne like that :


 

$pattern = '(?s).+?(\d+)\]\[([^\]]+).+?Bonjour,\s+(.+?) vous envoie.+?email : (\N+).+?tél. : (\N+)'

$pattern = '(?s).+?(\d+)\]\[([^\]]+).+?Bonjour,\s+(.+?) vous envoie.+?email : (\N+)'

 

This is an exemple of what I want to exctract (I want blue values ) :

 

[BLABLA][60][Demandeur][4567_987654]

Bonjour,
Charles HENRY vous envoie un message.
J'ai un problème de toilette
Merci de m'aider
- email : Jordane.AutoIT@AutoITForum.com
- tél. : 0607080909

I had that and it was working very fine.

 

=============================================

 

Now my text content changed :

It's now like that :

 

[BLABLA][PO][60][Demandeur][4567_987654]

Bonjour,
Charles HENRY vous envoie un message.
J'ai un problème de toilette
Merci de m'aider
- email : Jordane.AutoIT@AutoITForum.com
- tél. : 0607080909

Or

 

[BLABLA][Autre][60][Demandeur][4567_987654]

Bonjour,
Charles HENRY vous envoie un message.
J'ai un problème de toilette
Merci de m'aider
- email : Jordane.AutoIT@AutoITForum.com
- tél. : 0607080909

 

For information :

BLABLA cannot change and will stay letters.

Autre or PO wont change

60 can be 01 to 980

 

Demandeur can be :

Demandeur Or Opérateur Or Pris Or Instructeur.

 

1000 thanks RegExp pro's ;)

 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

@caramen
Maybe something like this?

#include <Array.au3>
#include <StringConstants.au3>

Global $strString = "[BLABLA][Autre][60][Demandeur][4567_987654]" & @CRLF & @CRLF & _
                    "Bonjour," & @CRLF & _
                    "Charles HENRY vous envoie un message." & @CRLF & _
                    "J'ai un problème de toilette" & @CRLF & _
                    "Merci de m'aider" & @CRLF & _
                    "- email : Jordane.AutoIT@AutoITForum.com" & @CRLF & _
                    "- tél. : 0607080909"
                    
Global $strPattern = "(?s)\[[^]]+\]\[[^]]+\]\[([^]]+)\]\[([^]]+)\]\[([^]]+)\].*?" & _
                     "Bonjour,\s*(.*?)(?=vous).*?" & _
                     "\-\s*email\s*:\s(\S+)\s*" & _
                     "\-\s*tél\.\s*:\s([^\n]+)"

Global $arrResult


$arrResult = StringRegExp($strString, $strPattern, $STR_REGEXPARRAYGLOBALMATCH)
If IsArray($arrResult) Then _ArrayDisplay($arrResult)

:)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Hey @FrancescoDiMuro Ho are you  ? :) Thanks giving me some if your time ;)

 

I 'll try right now and let you know.

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

@FrancescoDiMuro Nop it does not work :(

My output is :

Name Surname | Email | Phone number | Po | Department

And i need :

Name Surname | Email | phone Number| Po | Folder number | Department

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Sorry my bad bro.

 

I got correct input without PO or AUTRE

But seem like my boss ust said me we dont need it.

 

I am done with that regexp TY Mate.

 

I was forgetting this : $STR_REGEXPARRAYGLOBALMATCH

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

@FrancescoDiMuro I am sorry mate it s not working as expected but it's my fault ;

I forgot to say you :

My input $hString can be :

"[BLABLA][AUTRE][60][Demandeur] Autre" & @CRLF & @CRLF & _
"Bonjour," & @CRLF & _
"Charles HENRY vous envoie un message." & @CRLF & _
"J'ai un problème de toilette" & @CRLF & _
"Merci de m'aider" & @CRLF & _
"- email : Jordane.AutoIT@AutoITForum.com" & @CRLF & _
"- tél. : 0607080909"

In this case i have no digit apearing. And i have 0 output.

Phew it was my exemple to code it so i noticed that before leave this site.

 

Btw I am trying with 101 regexp but i non stop failing. I have no time to undertsand the correct syntaxt arfff

 

If it is possible for you to help me to make the pattern work for both possibility 😕 Man thanks again and sorry.

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

I thought i did at my first post :) Just forgot that i can have no digit i am sorry mate it's becose it's been a long i was not in this building so i forgot some details.

 

For your confort I will repeat and i hope i wont miss something :

 

[BLABLA][PO][60][Demandeur][4567_987654] Bliblo blop Random texte here
Bonjour,
Charles HENRY vous envoie un message.
J'ai un problème de toilette
Merci de m'aider
- email : Jordane.AutoIT@AutoITForum.com
- tél. : 0607080909

Or

[BLABLA][Autre][60][Demandeur][4567_987654]Random texte here
Bonjour,
Charles HENRY vous envoie un message.
J'ai un problème de toilette
Merci de m'aider
- email : Jordane.AutoIT@AutoITForum.com
- tél. :

Or

[BLABLA][Autre][60][Demandeur]Autre question
Bonjour,
Charles HENRY vous envoie un message.
J'ai un problème de toilette
Merci de m'aider
- email : Jordane.AutoIT@AutoITForum.com
- tél. : 0607080909

Or

[BLABLA][PO][60][Prise][4567_987654]Autre question
Bonjour,
Charles HENRY vous envoie un message.
J'ai un problème de toilette
Merci de m'aider
- email : Jordane.AutoIT@AutoITForum.com
- tél. :

 

For information :

Demandeur can be :

Demandeur Or Opérateur Or Prise Or Instructeur :

PO Can be PO or PSC Or AUTRE

The téléphone can be here or not.  (Already solved with string split)

Thanks mate 1000x !

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

If those strings, 'Bonjour' prior to the name and 'vous' after, are static then it makes it easier (at least for me) if all whitespace is removed.  The only other assumption is the capitalization of the first letter of the name, but you could always sanitize that line first.

#include<array.au3>

Global $strString = "[BLABLA][Autre][60][Demandeur][4567_987654]" & @CRLF & @CRLF & _
                    "Bonjour," & @CRLF & _
                    "Charles HENRY vous envoie un message." & @CRLF & _
                    "J'ai un problème de toilette" & @CRLF & _
                    "Merci de m'aider" & @CRLF & _
                    "- email : Jordane.AutoIT@AutoITForum.com" & @CRLF & _
                    "- tél. : 0607080909"


$aMatch = stringregexp(StringStripWS($strString , 8) , "\[.*?\]\[.*?\]\[(.*?)\]\[(.*?)\]\[(.*?)\]Bonjour,([A-Z].+?)([A-Z].+?)vous.*?email:(.*?)-tél.:(.*?)\z",3)

_ArrayDisplay($aMatch)

 

Edited by iamtheky
script rather than just regex

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

@FrancescoDiMuro

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

@iamtheky Ty man let me try. that.

 

I have all i want and the only thing missing is the file number.

And the Francesco pattern is working very fine expet if i have no digit inside the first line.

 

hmmm one min i com eback to say you.

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

@iamtheky Sorry dude it does not work at all.

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\yann.lebrun\Desktop\Nouveau AutoIt v3 Script.au3"    
>Exit code: 0    Time: 0.1185

I mean it does not work if there is no digit **

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

working_script.thumb.PNG.21c07968b639d3418e29930e7f345d42.PNG

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Bro this is already working. My issue is when the folder number is missing becose it happen sometime. Look above post you will see all case possible. ;)

This is the non working case :

And i have to make these two case work With and without digit.

[BLABLA][Autre][60][Demandeur]Autre question
Bonjour,
Charles HENRY vous envoie un message.
J'ai un problème de toilette
Merci de m'aider
- email : Jordane.AutoIT@AutoITForum.com
- tél. : 0607080909

 

 

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

We can be in these cases :

 

[BLABLA][PO][60][Prise][4567_987654]Autre question
[BLABLA][PO][60][Prise]Autre question
[BLABLA][AUTRE][60][Prise][4567_987654]Autre question
[BLABLA][PO][60][Demandeur]Autre question

And the rest of the text and we have already a working pattern for this.

I tryed a lot of thing in regexp101 but i cant get so long syntaxt work for me even with the help of the website i am non stoping to try since 3 hours^^

 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Just now, FrancescoDiMuro said:

@caramen

Make that group optional adding a ? after the group :)

ok 😛 i am trying now so give me one min^^

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

7 minutes ago, FrancescoDiMuro said:

@caramen

Make that group optional adding a ? after the group :)

Well i tryed all position for the "?" between each single characters and nop nothing is extracted

 

Maybe i can ubund the total line after a string split and if ubund = > 4 then i get the last bracket ?

I would prefer a regexp but seem like it doesn't come

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

 I am not attempting to question the efficacy of your chosen path, nor generate a solution.  Just trying to show you how to make things optional inline, which is easier to highlight in this fashion.  Is this closer to feasible for an example?

#include<array.au3>



Global $strString2 = "[BLABLA][Autre][60][Demandeur][4567_987654]" & @CRLF & @CRLF & _
                    "Bonjour," & @CRLF & _
                    "Charles HENRY vous envoie un message." & @CRLF & _
                    "J'ai un problème de toilette" & @CRLF & _
                    "Merci de m'aider" & @CRLF & _
                    "- email : Jordane.AutoIT@AutoITForum.com" & @CRLF & _
                    "- tél. : 0607080909"

Global $strString3 = "[BLABLA][Autre][60][Demandeur]autere" & @CRLF & @CRLF & _
                    "Bonjour," & @CRLF & _
                    "Charles HENRY vous envoie un message." & @CRLF & _
                    "J'ai un problème de toilette" & @CRLF & _
                    "Merci de m'aider" & @CRLF & _
                    "- email : Jordane.AutoIT@AutoITForum.com" & @CRLF & _
                    "- tél. :"


Global $strString4 = "[BLABLA][Autre][60][Demandeur]" & @CRLF & @CRLF & _
                    "Bonjour," & @CRLF & _
                    "Charles HENRY vous envoie un message." & @CRLF & _
                    "J'ai un problème de toilette" & @CRLF & _
                    "Merci de m'aider" & @CRLF & _
                    "- email : Jordane.AutoIT@AutoITForum.com" & @CRLF & _
                    "- tél. : "



$aMatch = stringregexp(StringStripWS($strString2 , 8) , "\[.*?\]\[.*?\]\[(.*?)\]\[(.*?)\]\[*(.*?)\]*?Bonjour,([A-Z].+?)([A-Z].+?)vous.*?email:(.*?)-tél.:(.*?)\z",3)

_ArrayDisplay($aMatch)

 

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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