mjolnirmarkiv Posted September 15, 2015 Share Posted September 15, 2015 (edited) 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 September 15, 2015 by mjolnirmarkiv Link to comment Share on other sites More sharing options...
jchd Posted September 15, 2015 Share Posted September 15, 2015 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 mjolnirmarkiv 1 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
mjolnirmarkiv Posted September 15, 2015 Author Share Posted September 15, 2015 (edited) Not quite, actual criteria I need to check is ".*?(.*?\)" i.e. "text text (text text)", I've replaced it with "\d+" for the simplicity. You inverted criteria with "\D*", so I'm not sure how I can do the same with ".*?(.*?\)". Edited September 15, 2015 by mjolnirmarkiv Link to comment Share on other sites More sharing options...
mjolnirmarkiv Posted September 15, 2015 Author Share Posted September 15, 2015 (edited) But you gave me an idea, this works: "<tag>(?(?=[^<]+?\h\([^<]+?\))(*FAIL)|(*ACCEPT))</tag>"... unless there're easier ways to do it? Edited September 15, 2015 by mjolnirmarkiv Link to comment Share on other sites More sharing options...
jguinch Posted September 15, 2015 Share Posted September 15, 2015 mjolnirmarkiv, could you give us some examples of matching and not matching strings ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
jchd Posted September 15, 2015 Share Posted September 15, 2015 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
mikell Posted September 15, 2015 Share Posted September 15, 2015 The dark side of the Force doesn't allow to present explicitely from the start the real requirements Link to comment Share on other sites More sharing options...
mjolnirmarkiv Posted September 15, 2015 Author Share Posted September 15, 2015 Sorry 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 More sharing options...
iamtheky Posted September 15, 2015 Share Posted September 15, 2015 (edited) 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 September 15, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mjolnirmarkiv Posted September 15, 2015 Author Share Posted September 15, 2015 boththose, yeah, I know, I've included "\x{200d}" in the regexp. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now