Jump to content

StringRegExp - again


Recommended Posts

$x = "*abc,def,mno,ghi" & @CRLF & "*jkl,mno" & @CRLF & "def" & @CRLF & "def" & @CRLF & "ghi" & @CRLF & "mno"

I would like a pattern to pick up the string between a "*" and the next "@CRLF"

I have tried very hard and got no where. :

There is no point me posting code that I have because - it does not work.

Can anyone help.

I could write some code to play around with the string and get my script to work - but I would really like to get to know how StringRegExp work :(

@Nutster

StringRegExp is something I would like to use more of. I have used it in one script where I was able to copy someone elses pattern file and modify it sligtly - but trying to create one from scatch has beaten me.

I thing one of the problems is that the help file is abit thin on the process of creating a pattern string.

Is it possible to write up a few examples to show how parts are joined together, when you use brackets and when you don't - perhaps examples of good practice and examples where it just works.

From your contibutions on the forum - I know you are busy - but this function (if we understood it !!) would be far more widely used. In the script I was able to get it to work in - it was brilliant - I would like to use it more often - but - I think I need a few pointers. :(

Thanks.

Link to comment
Share on other sites

w0uter,

Thankyou for yor reply :(

I tried -

$x = "*abc,def,mno,ghi" & @CRLF & "*jkl,mno" & @CRLF & "def" & @CRLF & "def" & @CRLF & "ghi" & @CRLF & "mno"
$pattern = "\*(*.?)" & @CRLF
$y = StringRegExp($x,$pattern,1)
MsgBox(0,"",@error  & @CRLF & @extended  & @CRLF & $y)

..and many variations of the pattern - but still no luck. :(

Link to comment
Share on other sites

StringRegExp is above my level but........... this may help

#include <GUIConstants.au3>

;$x = "*abc,def,mno,ghi" & @CRLF & "*jkl,mno" & @CRLF & "def" & @CRLF & "def" & @CRLF & "ghi" & @CRLF & "mno"

;your pattern as stated would return this

;$x1 = *abc,def,mno,ghi" & 

;$x2 = *jkl,mno" & 

; the rest would not show as there are no more accurances with an "*"

;so, if you use a similar "@" for the begining and ending of the patern, you could use this

$x = "abc,def,mno,ghi" & @CRLF & "jkl,mno" & @CRLF & "def" & @CRLF & "def" & @CRLF & "ghi" & @CRLF & "mno"

$x1 = StringSplit( $x, "@") 

For $disp = 1 to $x1[0]
    
MsgBox(0,"Results", $x1[$disp])

Next

; >>>>>>>>> or

$x = "abc,def,mno,ghi" & @CRLF & "jkl,mno" & @CRLF & "def" & @CRLF & "def" & @CRLF & "ghi" & @CRLF & "mno"

$x1 = StringSplit( $x, "o") 

For $disp = 1 to $x1[0]
    
MsgBox(0,"Results", $x1[$disp])

Next

i think the out-come was what you wanted

enjoy!

8)

NEWHeader1.png

Link to comment
Share on other sites

@Valuater

Thankyou for the reply.

I posted the last code because it did not work - but after your comments I thought that it must be me that was the problem and not the script.

After - a little bit more playing (well - quite a lot really!!) I made a slight alteration to $pattern

$x = "*abc,def,mno,ghi" & @CRLF & "*jkl,mno" & @CRLF & "def" & @CRLF & "def" & @CRLF & "ghi" & @CRLF & "mno"
$pattern = "\*(.*?)" & @CRLF
$y = StringRegExp($x,$pattern,3)
MsgBox(0,"",@error  & @CRLF & @extended  & @CRLF & $y[0]& @CRLF & UBound($y))

This will now pick up the first set of letters OK ie "abc,def,mno,ghi"

but it does not pick up the second set ie "jkl,mno"

Any thoughts.

Thanks

Link to comment
Share on other sites

$x = "*abc,def,mno,ghi" & @CRLF & "*jkl,mno" & @CRLF & "def" & @CRLF & "def" & @CRLF & "ghi" & @CRLF & "mno"
$pattern = "\*(.*?)\s"
$y = StringRegExp($x,$pattern,3)
For $i = 0 to Ubound($y)-1
    MsgBox(0,"",@error  & @CRLF & @extended  & @CRLF & $y[$i]& @CRLF & $i)
Next

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

Actually w0uter, you should use \n instead of \s.

\n matches new lines and carriage returns

\s matches whitespace

$x = "*abc,def,mno,ghi" & @CRLF & "*jkl,mno" & @CRLF & "def" & @CRLF & "def" & @CRLF & "ghi" & @CRLF & "mno"
$pattern = "\*(.*?)\n"
$y = StringRegExp($x,$pattern,3)
For $i = 0 to Ubound($y)-1
    MsgBox(0,"",@error  & @CRLF & @extended  & @CRLF & $y[$i]& @CRLF & $i)
Next

And there you have it.

*Edit: This page provides some good information/examples on using regular expressions. The syntax may not match AutoIt's exactly, but it should be similar enough for you to get a good idea of how to use it.

Edited by Saunders
Link to comment
Share on other sites

Actually w0uter, you should use \n instead of \s.

\n matches new lines and carriage returns

\s matches whitespace

yeah i should actually but \s works fine for this ex.

\s Match any whitespace character: Chr(9) through Chr(13) which are Horizontal Tab, Line Feed, Vertical Tab, Form Feed, and Carriage Return, and the standard space ( Chr(32) ).

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

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