Jump to content

-deleted-


Guest Plemdsan
 Share

Recommended Posts

you might want to read through this: PCRE Specs

also you might want you use capture brackets '()' to capture exactly what you want.

also in the directory "program files\autoit3\examples\helpfile" there is a file "StringRegExpGUI.au3" you can use that to test the regexp engine, the radio button options are (top to bottom) 0,1,3

[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Link to comment
Share on other sites

Hello JBtje,

SRE can be a fickle thing, and I have found it to be one of the most difficult functions in AutoIt to learn and understand.

First, Your third example is a correct way to obtaining the result you want for the First example. Reason your third example is incorrect is your asking it to capture what is inside [], /r=Carriage Return or @CR, /n = linefeed or @LF, so your asking it to capture @CRLF. Reason for the first is your asking it to Capture everything but '.' repetitively '+', and any combinations of 'how' so your end result from $data would be 'how'. This example which is your third, is what you want.

$zz1 = StringRegExp( $data, '[\r\n.]+', 1)
MsgBox(0,"1",$zz1[0])

In your Second example, your asking it to capture '.' since there are no periods in your $data string, you will result with nothing. In order to capture just the first word, these to examples will do the trick:

$zz2a = StringRegExp( $data, '(.*?)' & @CRLF, 1)
$zz2b = StringRegExp( $data, '[^/r/n]+' & @CRLF, 1)
MsgBox(0,"2","First Example= " & $zz2a[0] & @CRLF _
            &"Second Example= " & $zz2b[0])

As for your third example, I explained what it does in my First example. I'm not sure exatly what your goal is here, but to take a guess, you want the sentence to be one line, and if I am correct, you could use:

$zz = StringRegExpReplace($data,@CRLF,' ')
msgbox(0, "3", $zz)

; if you need a linefeed at the end, then return as
$zz = StringRegExpReplace($data,@CRLF,' ') & @CRLF
MsgBox(0,"3",$zz)

I hope this helps.

Realm

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

The first example actually returns

hello

world

how

For me

In the second the dot will be read as a litteral when used in square brackets by the way.

StringRegExp($data, "^\b\w+\b\v", 1) gets the first word.

I don't know why you would ever have to use an SRE to return everything ($data already holds it) but if that's what you want then

StringRegExp($data, "(?s)^.+$", 1) will do it.

Look in my signature for the PCRE Toolkit to test SREs and SRERs

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Developers

Why would u want a "." behave differently within square braces, than outside of it? That makes no sense to me.... how come its done this weird way?

From the helpfile:

Matching Characters

[ ... ] Match any character in the set. e.g. [aeiou] matches any lower-case vowel. A contiguous set can be defined using a dash between the starting and ending characters. e.g. [a-z] matches any lower case character. To include a dash (-) in a set, use it as the first or last character of the set. To include a closing bracket in a set, use it as the first character of the set. e.g. [][] will match either [ or ]. Note that special characters do not retain their special meanings inside a set, with the exception of \\, \^, \-,\[ and \] match the escaped character inside a set.

You will find the same in the official docs for PCRE.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You didn't post any of your actual code for us to analyze what seems to be happening here and without that we can't help you.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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