Jump to content

[SOLVED] PCRE Regular expression match but ignore string in between


Kyan
 Share

Recommended Posts

so using .* would only match the last one? (I thought that quantifier matches 0 or more times)

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

It greedily matches as much as possible (i.e. almost everything) but backtracks so that the rest of the regexp matches (if possible). That uses some cycles but not a big problem with our CPUs, unless you feed very long input (and even then...).

What hapened when you tried it?

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)

Link to comment
Share on other sites

 

Expected Match: ISO/IEC 11770-2:2008/Cor.1:2009(E)
Expected Output: ISO/IEC 11770-2:2009(E)

#1 GlobalMatch Mode: (?i)((?:bs )?(?:en )?(?:np )?(?:is[o0]|DIN)\V{1,10}[-\d]+)(.+:)?(\d{4}(?:\(\w\))?)
output:

Spoiler
Row|Col 0
[0]|ISO/IEC 11770-
[1]|2:
[2]|2008
[3]|ISO/IEC 11770-
[4]|2:
[5]|2008
[6]|ISO/IEC 1
[7]|
[8]|1770
[9]|ISO/IEC 11770-2
[10]|:2008/Cor.1:
[11]|2009(E)

PHPMatchMode:
Row|Col 0
[0]|ISO/IEC 11770-2:2008
[1]|ISO/IEC 11770-
[2]|2:
[3]|2008

On [3] should have been: 2009(E)

#2 On global match (3), greedy match: (?i)((?:bs )?(?:en )?(?:np )?(?:is[o0]|DIN)\V{1,10}[-\d]+)(.*:)?(\d{4}(?:\(\w\))?)

Spoiler
Row|Col 0
[0]|ISO/IEC 11770-2
[1]|:
[2]|2008
[3]|ISO/IEC 11770-2
[4]|:
[5]|2008
[6]|ISO/IEC 1
[7]|
[8]|1770
[9]|ISO/IEC 11770-2
[10]|:2008/Cor.1:
[11]|2009(E)

Same regexp PHP match (2):

Row|Col 0
[0]|ISO/IEC 11770-2:2008
[1]|ISO/IEC 11770-2
[2]|:
[3]|2008

The thing is that it never outputs the same number of rows. The only possibility I see is to use to output: $a[ubound($a)-3]&$a[ubound($a)-1] to always output the "Expected Output".

#1 and #2 end up with the same matches (using in the first the "+" and in the last "*")

 


The things change when I only use "*": (?i)((?:bs )?(?:en )?(?:np )?(?:is[o0]|DIN)\V{1,10}[-\d]*)(.*:)?(\d{4}(?:\(\w\))?)

Global Matches (3):

Spoiler
Row|Col 0
[0]|ISO/IEC 11770-2
[1]|:
[2]|2008
[3]|ISO/IEC 11770-2
[4]|:
[5]|2008
[6]|ISO/IEC 1
[7]|
[8]|1770
[9]|ISO/IEC 
[10]|
[11]|8825
[12]|ISO/IEC 
[13]|
[14]|2009
[15]|ISO/IEC 11770-2
[16]|:2008/Cor.1:
[17]|2009(E)

 

PHP Match:

Spoiler
Row|Col 0
[0]|ISO/IEC 11770-2:2008
[1]|ISO/IEC 11770-2
[2]|:
[3]|2008

 

 

Edited by Kyan

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

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

×
×
  • Create New...