Jump to content

What I am I doing wrong related to StringRegExp


Go to solution Solved by mLipok,

Recommended Posts

Posted

Hello everybody,

I am wondering if anybody could help me or tell me what I am doing wrong..

I try to capture some text out of a text file...

This is the content of the text file :

Unités g/L : Méthode : HAPT Date/Heure : 2013-03-21 15:38:41 Etat : Etendu ID appareil : DV330681

What I want to capture is "HAPT" everything after "Méthode : " and before " Date/Heure"

This is the code that i have until now:

Func _Calibratie()
Global $reY = StringRegExp(FileRead($file), 'Méthode :\s+(\S+)',0)
Global $reT = StringRegExp(FileRead($file), 'Méthode :\s+(\S+)',3)

Msgbox(64,"CAL",$reY)

Msgbox(64,"CAL",$reT)

When i run the code the result of $reY = 1 (for me this means that it found the string correctly)

However the result of $reT is nothing/ empty..

does anybody has any idea what i am doing wrong ?

Many thanks for all help..

Kindly regards,

Koen

Posted

$reT is an array.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

  • Solution
Posted

try this:

Global $reT = StringRegExp(FileRead($file), '(?i)Méthode :\s+(.*?)Date/Heure',3)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Hello first of thanks for the reply,.

 

@mlipok, When I try your code I stil got to result for the $reT

 

@BrewManNH, can you explain how to get it working?

 

Thanks a lot,

Koen

Edited by Melba23
Fixed font size
Posted (edited)

Hello,

here is some more information...

Global $Method = StringRegExp(FileRead($file), '(?i)Méthode :\s+(.*?)Date/Heure',3)
_ArrayDisplay($Method)
FileMove($orgnamepath & "\" & $rcvname & ".pdf", $finamepath & "\" & $prefixC & "_" & $Method & ".pdf",1)
When I am doing a QrrqyDisplqy I can see the correct result now ( thanks to BrewManNH and mlipok);

but how can i transfer this result into a variable so that I can use this to create example a filename?

Thanks a lot for all support...

Koen

Edited by Melba23
Fixed font size
  • Moderators
Posted

koenp,

Please use the standard size font - putting everything into subscript makes it too small to read comfortably. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Look at the return from StringRegExp when using option flag 3, the returned information is contained in an array, you can not display it in a MsgBox the way you're trying to do it. Using option flag 0 it returns true or false (1 or 0) so you can display that in the msgbox to tell you it found the information you're looking for.

If you're unfamiliar with how to handle information in an array, I would look here to read up on them.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted (edited)

@koenp

I would recommend you read this:
 
in particular:
Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

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