Jump to content
Sign in to follow this  
Tom42

StringRegExp syntax

Recommended Posts

Tom42

this is what I'm trying to do

Create multiple arrays base off file types (file names)

Grab a list of files from a directory using FileListToArray

Posted Image

convert the array to a string (FileListToArray allows for wildcards not RegExp)

Filter string putting files that are 4 digits followed by ".fsh" in a new array

Posted Image

The next filter is where I'm screwing up, it is most likely a simple syntax error

This filter should create an array of files that start with a "c" then 3 digits and ending with either ".fsh", ".orl", or ".ord". But this is my result

Posted Image

Here is my au3 code

#include <String.au3>
#include <array.au3>
#include <file.au3>

$FileList = _FileListToArray(@ScriptDir)
_ArrayDisplay($FileList, 'StringRegExp Search')

$newlist = _ArrayToString ( $FileList, ";")

$aArray2 = StringRegExp ( $newlist, '(\d\d\d\d.fsh)',3)
_ArrayDisplay($aArray2, 'StringRegExp Search')

$Faces = StringRegExp ( $newlist, '(c\d\d\d.(fsh|orl|ord))',3)
_ArrayDisplay($Faces, 'StringRegExp Search')

I could convert that array to a string and use StringRegExp to grab all files that is 1 letter, 3 digits, a "." then 3 letters, but I would really like to know what I'm doing wrong

Share this post


Link to post
Share on other sites
jefhal

c\d{3}.(fsh|orl|ord)

this seems to work

You might want to check out the regexp editor called Expresso 3.0 Beta...

Edited by jefhal

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites
SmOke_N

The \d.

You're telling it to get the next character regardless what it is .

...

Do you have an example list we don't have to write out ourselves on how StringRegExp() is going to see the string?


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.

Share this post


Link to post
Share on other sites
jefhal

Hi Sm0ke_N-

I think my regexp solves his problem...


...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites
SmOke_N

Hi Sm0ke_N-

I think my regexp solves his problem...

I didn't see your post before I posted, but taking away the brackets will help for sure.

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.

Share this post


Link to post
Share on other sites
SmOke_N

Hi Sm0ke_N-

I think my regexp solves his problem...

Actually, that doesn't do what he wanted to do...

#include <array.au3>
$sFile = FileRead(@ScriptDir & '\testing.txt')
$aCArray = StringRegExp($sFile, '\W(c\d{3}\.fsh|c\d{3}\.orl|c\d{3}\.ord)(?m:\r|$)', 3)
_ArrayDisplay($aCArray, 'c')
I think is more of what he was after.

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.

Share this post


Link to post
Share on other sites
Tom42

Actually, that doesn't do what he wanted to do...

#include <array.au3>
$sFile = FileRead(@ScriptDir & '\testing.txt')
$aCArray = StringRegExp($sFile, '\W(c\d{3}\.fsh|c\d{3}\.orl|c\d{3}\.ord)(?m:\r|$)', 3)
_ArrayDisplay($aCArray, 'c')oÝ÷ Øay"²j+zð«a{¬iû^¯ú®¢×ºÚ"µÍÚ[ÛYH  ÔÝ[Ë]LÉÝÂÚ[ÛYH  Ø^K]LÉÝÂÚ[ÛYH Ù[K]LÉÝÂÌÍÑ[SÝHÑ[SÝÐ^JØÜBÐ^^J  ÌÍÑ[SÝ  ÌÎNÔÝ[ÔYÑ^ÙXÚ   ÌÎNÊBÌÍÛ]ÛÝHÐ^UÔÝ[È
    ÌÍÑ[SÝ  ][ÝÎÉ][ÝÊBÌÍØP^LHÝ[ÔYÑ^
    ÌÍÛ]ÛÝ ÌÎNÊ ÌLÙ   ÌLÙ   ÌLÙ   ÌLÙÚ
IÌÎNËÊBÐ^^J ÌÍØP^L   ÌÎNÔÝ[ÔYÑ^ÙXÚ   ÌÎNÊBÌÍÑXÙÈHÝ[ÔYÑ^
    ÌÍÛ]ÛÝ ÌÎNÉÌLÕÊÉÌLÙÌßIÌLËÚÉÌLÙÌßIÌLËÜÉÌLÙÌßIÌLËÜ
JÛNÌLÜ   ÌÍÊIÌÎNËÊBÐ^^J   ÌÍÑXÙË ÌÎNÔÝ[ÔYÑ^ÙXÚ   ÌÎNÊoÝ÷ ÚØZ¶¯zÉÞ²ém±ú+¶¥jËZ®¶²êÞƬjjezÇ­¡÷âë.®

gives me this

Posted Image

Share this post


Link to post
Share on other sites
SmOke_N

#include <String.au3>
#include <array.au3>
#include <file.au3>

$FileList = _FileListToArray(@ScriptDir)
_ArrayDisplay($FileList, 'StringRegExp Search')

$newlist = _ArrayToString ( $FileList, ";")

$aArray2 = StringRegExp ( $newlist, '(\d\d\d\d.fsh)',3)
_ArrayDisplay($aArray2, 'StringRegExp Search')

$Faces = StringRegExp ( $newlist,'\W(c\d{3}\.fsh|c\d{3}\.orl|c\d{3}\.ord)(?m:\r|$)',3)
_ArrayDisplay($Faces, 'StringRegExp Search')oÝ÷ ÚØZ¶¯zÉÞ²ém±ú+¶¥jËZ®¶²êÞƬjjezÇ­¡÷âë.®oÝ÷ Ú¯zɶ¬h!¶Úþ) Û⨲ë?h6çõç®?kmkJgø¦ú®¢×v'gßÛaj÷+-¡÷âëÒ0jÉ÷öÛ¬x±é¢rhÚ,z«j×­æ«­¬­¡«-®)à#¬ºÈ§§®¸êÞ¶êçjwZ)Þ}ç²aÇhzȧ}§-+Þ¶«m¢ëiºÖ¥*.Â¥v¯z¶vÞÇ!jx¶ªºjºm $K«­¢+Ø¥¹±Õ±ÐíÉÉä¹ÔÌÐì(¥¹±Õ±Ðí¥±¹ÔÌÐì((ÀÌØí¥±1¥ÍÐô}¥±1¥ÍÑQ½ÉÉä¡MÉ¥ÁѥȤ)}ÉÉå¥ÍÁ±ä ÀÌØí¥±1¥ÍаÌäíMÑÉ¥¹IáÀMÉ Ìäì¤((ÀÌØí¹Ý±¥ÍÐô}ÉÉåQ½MÑÉ¥¹ ÀÌØí¥±1¥Íа
I1¤((ÀÌØíÉÉäÈôMÑÉ¥¹IáÀ ÀÌØí¹Ý±¥ÍаÌäìÀäÈíìÍô¹Í Ìäì°Ì¤)}ÉÉå¥ÍÁ±ä ÀÌØíÉÉäÈ°ÌäíMÑÉ¥¹IáÀMÉ Ìäì¤((ÀÌØíÌôMÑÉ¥¹IáÀ ÀÌØí¹Ý±¥ÍаÌäìÀäÈí¡ÀäÈíìÍôÀäÈì¹Í¡ñÀäÈíìÍôÀäÈ칽ɱñÀäÈíìÍôÀäÈ칽ɤ ý´èÀäÈíÉðÀÌØì¤Ìäì°Ì¤)}ÉÉå¥ÍÁ±ä ÀÌØíÌ°ÌäíMÑÉ¥¹IáÀMÉ Ìäì

Edit:

Had to change the directory back from what I was using.

Edited by SmOke_N

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.

Share this post


Link to post
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
Sign in to follow this  

×