Jump to content
Sign in to follow this  
Vossen

StringRegExp

Recommended Posts

Vossen

Hi,

I need some help as I never really got StringRegExp.

I get text like e.g.

["I WANT THIS","I WANT THIS","I WANT THIS",I WANT THIS]I WANT THIS

or

["I WANT THIS","I WANT THIS","I WANT THIS",I WANT THIS]I WANT THIS["I WANT THIS","I WANT THIS","I WANT THIS",I WANT THIS]I WANT THIS["I WANT THIS","I WANT THIS","I WANT THIS",I WANT THIS]I WANT THIS

When doing this...

StringRegExp($aFile[$i], '(?i)["(.*?)","(.*?)","(.*?)",(.*?)](.*?)', 1)

It returns: I WANT THIS","I WANT THIS","I WANT THIS",I WANT THIS]I WANT THIS

Then I tried...

StringRegExp($aFile[$i], '(?i)["([^"]+)","([^"]+)","([^"]+)",([^"]+)](.*?)', 1)

But then it returns nothing... Please help, my brain fried. Did I completely misunderstand the concept of RegExp? :blink:

// Vossen

Share this post


Link to post
Share on other sites
Bowmore

This should will work for your sample data.

#include <array.au3>
$Test = '["I WANT THIS","I WANT THIS","I WANT THIS",I WANT THIS]I WANT THIS["I WANT THIS","I WANT THIS","I WANT THIS",I WANT THIS]I WANT THIS["I WANT THIS","I WANT THIS","I WANT THIS",I WANT THIS]I WANT THIS'

$aMatches = StringRegExp($Test,["\][,]+([^"\][,]+)',3)
_ArrayDisplay($aMatches)

Edit: Minor modification to regular expression

Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites
Vossen

It seems to work for my use, thank you! I am not sure I ever will get RegExp. :blink:

Edit: The new one seems to miss a part though. ;)

Edited by Vossen

Share this post


Link to post
Share on other sites
seandisanti

It seems to work for my use, thank you! I am not sure I ever will get RegExp. :blink:

Edit: The new one seems to miss a part though. ;)

i still struggle with them sometimes, at the bottom of the string regular expression tutorial in the help file there is a tool that has helped me A LOT. StringRegExpGUI.au3 there's a button to load it into scite and then run, and it will let you test patterns etc against sample data etc. The tutorial is a pretty good one for the basics too

Share this post


Link to post
Share on other sites
GEOSoft

If you look in my signature there is a PCRE toolkit that will test your regular expressions against data from several sources.


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!"

Share this post


Link to post
Share on other sites
Vossen

Couldn't make Bowmore's try act 100% as I wanted it to, but thanks to GEOSoft I was able to test all sorts of lame ideas and somehow I made it work. :blink: Thanks.

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  

×