Jump to content

Recommended Posts

Posted

I want to parse some text using StringRegExp. Here is my text:

SMITH,A H00005207 HT: 165 WT: 61. .1 235 cm Kg AGE/SEX: 27/F BSA: 1.68 LOC m2 R/B : W5TH :

Here is my code:

$chars = FileRead($hFile)

$sPTnum = StringRegExp($chars,"H[0-9]{8}")

ConsoleWrite("error:" & @error & @CRLF)

ConsoleWrite("PTnum: " & $sPTnum & @CRLF)

The problem is that the RegExp does not return a match. If I use a tool like Expresso to test the RegExp it works fine. What am I doing wrong?

Posted

Thanks. I had read the description and tried accessing the array, but I was still not getting a match. The problem was with my text. It is generated via OCR and there O's where there should have been 0's and thus no match.

  • Moderators
Posted (edited)

#include <Array.au3> ; For Array display only

Global $s_fread = FileRead("File")
Global $a_data = StringRegExp($s_fread, "\w((?:o|O|\d){8})", 3)
; Fix Bad Char(s)
For $i = 0 To UBound($a_data) - 1
    $a_data[$i] = StringReplace($a_data[$i], "o", "0")
Next

_ArrayDisplay($a_data)

Edited by SmOke_N
Fixed Code Tags

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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