Sign in to follow this  
Followers 0
confused2gether

StringRegExp Help

5 posts in this topic

#1 ·  Posted (edited)

I am stuck at a certain point in my program that I need to extract a set of numbers from a specific string.

Here is are examples of some strings:

This is a (23.123, 34.567) great example of some code (yes it is).

This is another example of some code (34.234, 78.123).

Hello World (45.678, 12.324) This is cool.

I need to extract out the (##.###, ##.###) from each different string. The position is always different and the numbers are always different but the format is always the same. Also, in the first example, I need to make sure to not grab the "(yes if is)".

I have been looking around the forums and the help file and it looks like the thing to use is StringRegExp but I am very confused on how to write out how to grab that information specifically.

Any help is appreciated!

Thanks

Edited by confused2gether

Share this post


Link to post
Share on other sites



try (\(\d+\.\d+,\s+\d+\.\d+\))


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

try (\(\d+\.\d+,\s+\d+\.\d+\))

Initial try looks like it works! Thanks for the help! It will help me better understand how this who RegEx actually works too for the future.

Share this post


Link to post
Share on other sites

Initial try looks like it works! Thanks for the help! It will help me better understand how this who RegEx actually works too for the future.

I didn't reply earlier because jchd had it all under control. If you want to learn and use Regular Expressions, try the PCRE Toolkit in my signature.

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

#5 ·  Posted (edited)

I've little to add to what GeoSoft said, but let me try to explain:

(\(\d+\.\d+,\s+\d+\.\d+\)) : the outer parenthesis actually mean capture what matches the inside.

\(\d+\.\d+,\s+\d+\.\d+\) : match a left parenthesis

\d+\.\d+,\s+\d+\.\d+\) : match one or more decimal digits

\.\d+,\s+\d+\.\d+\) : match a dot

\d+,\s+\d+\.\d+\) : match one or more decimal digits

,\s+\d+\.\d+\) : match a comma

\s+\d+\.\d+\) : match one or more space character

\d+\.\d+\) : match ###.### like we just did

\) : match a right parenthesis

It's just like Lego bricks!

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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  
Followers 0