Jump to content

Yet another one RegExp request


Recommended Posts

Hello,

Have been thinking about this for a while, so decided to seek for help.

I have the following string: "...<tag>1</tag>...<tag>2</tag>...<tag>3</tag>...", which I need to test if all text within <tag> matches certain criteria, e.g. it's a number "\d+". The trick is 1) I need the entire match to fail if only one instance of the text between <tag> doesn't match "\d+"; 2) I need the string to match if there's no <tag>.

E.g.:

- "...<tag>1</tag>...<tag>2</tag>...<tag>3</tag>..." matches.
- "...<tag>a</tag>...<tag>2</tag>...<tag>3</tag>..." fails.
- "..." matches.

Thanks!

Edited by mjolnirmarkiv
Link to comment
Share on other sites

This?

Local $aTest = [ _
    "...<tag>1</tag>...<tag>2</tag>...<tag>3</tag>...", _
    "...<tag>1</tag>...<tag></tag>...<tag>3</tag>...", _
    "...<mytag>""1""</mytag>...<yourtag></yourtag>...<ourtag>3</ourtag>...", _
    "...nothing important here...", _
    "...<tag>a</tag>...<tag>2</tag>...<tag>3</tag>..." _
]

For $s In $aTest
    ConsoleWrite($s & (StringRegExp($s, '<tag>\D*</tag>') ? ' fails' : ' matches') & @LF)
Next

 

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

I give up aiming at targets instantly teleporting themselves thru hyperspace.

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

Sorry :D

Here're couple of examples of matched strings:

text <‍tag>text (text)<‍/‍tag> text <tag>text (text)</tag> text.
text text text text text.

And here's failed string:

text <‍tag>text<‍/‍tag> text <tag>text (text)</tag> text.

In other words, no words in brackets within <tag> = fail.

 

But nevermind, jchd gave me an idea, so I consider this one closed. Following regexp should work: "<tag>(?![^<]+?\h\([^<]+?\))" -- I just need to invert its logic.

Link to comment
Share on other sites

You have zero width white spaces Joiners in your strings.  I dont know how much that will muck up the water, but a stringstripws may be helpful wont do anything, maybe delete all the 8205s from an ascii array or stringreplace?

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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