regex 'lazy' eye-opener needed

4 posts in this topic

#1 ·  Posted (edited)

I could use a lesson in laziness... ;)

I sometimes come across this problem where I think I need to use regex 'lazy' and the stuff I'm trying doesn't work, cos I need an eye-opener example for one of my typical problems...

As an example a string of text where I *only* want the red spaces selected (or have a usable $1 and $2) after each piece of "quoted text" longer than 6 characters:

"12345!" Txt "12345!" Txt "123456789!" Txt "12345!" Txt "12345!" Txt "12345678!" Txt

The problem with what I'm trying is that it seems greedy and the selection doesn't stop at the first quote character (going backwards)...
I try '(?U)' and other stuff, but not seeing the light yet...

This is *not* what I want. I want the "12345!" instances ignored... (BTW: don't use '\d', cos it could be anything inside the quotes)

TIA :)

Edited by Guy_

Share this post

Link to post
Share on other sites

#3 ·  Posted (edited)

Can you try this ?

Yes, I got that to work for my purposes :) It may have a tiny mistake (or not) with the quotes, that I seem to have corrected.
I also got the impression that there are two types of typographers quotes that look exactly alike in some fonts and therefore I had to experiment a bit...

So it seems it had nothing to do with 'laziness' and you used another technique (with help of the exclusions, is my guess.)
I needed to understand that better too, so that will help me many times.

BTW: My intention was to double up the spaces behind the longer quotes, so I can now replace with "$1 "


Edited by Guy_

Share this post

Link to post
Share on other sites

Don't use lazy, use not. For example to get stuff between quotes use:


This means: Match a quote followed by anything that is not a quote a number of times followed by a quote.

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

  • Similar Content

    • tezhihi
      By tezhihi
      I have a file (see attached file) with a string all line and this problem on here is I want to separate all $00:, $03:, $10:, $20:, $25:, $30:, $40:, $45:, $110:, $115:, $120: and $T. It's mean that each $ with value start a new line ( a new paragraph). I tried with Regular Expression in notepad++ ex:
      Find ($00:, $01:, $03: and so on) with regex (\$)([0-9]+): and replace is \r\n\1\2 (I think \r\n is @CRLF (not sure :() ) Find $T with regex (\$T)(.*?)(\$T) and replace is \1\2\r\n\3 When I try these regex to replace in notepad on StringRegexReplace the results is incorrect . I have read some example simple about regex. Please advise me how to do that with some example on autoit . The result will be in attached photo. Thanks 

    • MyEarth
      By MyEarth
      Hello, i need to validate a string can be different things. I just need a True - False return value, no groups or things like that. It will be always one line at time to be processed by StringRegEx
      02:52 XX|String
      13:52~SUN, MON, TUE, WED, THU, FRI, SAT|String
      02:52 XX~SUN, MON, FRI|String
      22/04/2017 13:52|String
      22/04/2017 02:52 YY|String
      Not Valid
      22/04/2017 13:52~Dom|String
      I need to validate until and inclusively the | after that i don't care
      The XX and YY value are two $sVariable from my script
      SUN, MON, TUE, WED, THU, FRI, SAT are fixed value, the can be mixed but always in the same order like
      SUN, TUE, WED
      SUN, SAT 
      The time can be 12 or 24 hours, the date is always in the same format DD/MM/YYYY. If there is a date can't be a day after that ( see not valid )
      Well i think is all
      Sorry if i don't provide a working code, regex is too way complex.
    • DavidLago
      By DavidLago
      I need to list only the folders that has a name composed of numbers only.
      How do I do this?
      OBS: I just posted the relevant content to the folder.
      Global $path = "G:\jobs\" For $i = 1 To $aArray[0] Local $search = FileFindFirstFile($path & $aArray[$i] & "\[0-9]" ) I tried with "\*.*" and it returns me the expected result, but the other doesn't.
    • nikink
      By nikink
      Hi all, it's been a while since I last used regular expressions and I find myself out of time to experiment with this particular issue, so I throw myself upon your mercy and expertise.
      I am looking to create a function that will say whether or not a supplied string is a valid UUID or not.
      Local $sTestF = '4C4C4544-004A-4C10-8054-B7C04F46343' Local $sTestT = '4C4C4544-004A-4C10-8054-B7C04F463432' ConsoleWrite('False = ' & _IsValidUUID($sTestF) & @CRLF) ConsoleWrite('True = ' & _IsValidUUID($sTestT) & @CRLF) Func _IsValidUUID($sUUID) ;[\p{XDigit}]{8}-[\p{XDigit}]{4}-[34][\p{XDigit}]{3}-[89ab][\p{XDigit}]{3}-[\p{XDigit}]{12} ; Test UUID = '4C4C4544-004A-4C10-8054-B7C04F463432' Local $sRegExp = '([:xdigit:]){8}\-([:xdigit:]){4}\-([34])([:xdigit:]){3}\-([89ab])([:xdigit:]){3}\-([:xdigit:]){12}' ConsoleWrite(StringRegExp($sUUID, $sRegExp) & @CRLF) Local $Result = StringRegExp($sUUID, $sRegExp) ConsoleWrite($Result & @CRLF) If @error Then ConsoleWrite('Error: [' & @error & ']' & @CRLF) Return 'False' Else ConsoleWrite('Error2: [' & @error & ']' & @CRLF) Return 'True' EndIf EndFunc In the line under the Function call, you'll see the regex I found to do this from a google search. That was my starting point, and I'm trying to get it to work in Au3 and failing miserably.
      $sTestF is a known invalid String
      $sTestT is a known valid String
      Everything I've tried so far has produced the same results for both.
      Any help you could provide me is greatly appreciated. Thanks for your time!
    • Trong
      By Trong
      I need help string RegEx to get string from CREATE to GO
      #include <StringConstants.au3> ;~ Global $fileSQL1 = @ScriptDir & "\fileSQL1.sql" ;~ Global $fileSQL2 = @ScriptDir & "\fileSQL2.sql" Global $tmpSQLfile = @TempDir & "\tmpFile.sql" OnAutoItExitRegister("_OnExit") _SetTMPsql() If Not FileExists($tmpSQLfile) Then OnAutoItExitUnRegister("_OnExit") Exit MsgBox(48, "/!\", "File: " & $tmpSQLfile & @CRLF & " is not Exists!", 3) EndIf Global $ContentSQLfile = FileRead($tmpSQLfile) _Start() Func _Start() Local $aArray, $iOffset = 1, $stringRegExp = '(?i)CREATE(.*?)GO' While 1 $aArray = StringRegExp($ContentSQLfile, $stringRegExp, $STR_REGEXPARRAYMATCH, $iOffset) If @error Then MsgBox(48, "StringRegExp Error " & @error, "+> StringRegExp: " & $stringRegExp & @CRLF & @CRLF & "=> With STRING:" & @CRLF & @CRLF & $ContentSQLfile) ExitLoop EndIf $iOffset = @extended For $i = 0 To UBound($aArray) - 1 MsgBox(0, "RegExp Test with Option 1 - " & $i, $aArray[$i]) Next WEnd EndFunc ;==>_Start Func _SetTMPsql() Local $tmpSQLContent = "" $tmpSQLContent &= "USE [Master]" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "CREATE DATABASE [Sales] ON PRIMARY " & @CRLF $tmpSQLContent &= "( NAME = N’Sales’, FILENAME = N’\FSASQLDBSales.mdf’ , " & @CRLF $tmpSQLContent &= " SIZE = 2GB , MAXSIZE = 8GB, FILEGROWTH = 1GB )" & @CRLF $tmpSQLContent &= "LOG ON " & @CRLF $tmpSQLContent &= "( NAME = N’Sales_log’, FILENAME = N’\FSASQLDBSales_log.ldf’ , " & @CRLF $tmpSQLContent &= " SIZE = 1GB , MAXSIZE = 2GB , FILEGROWTH = 10%)" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "USE [Sales]" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "-- Table Product" & @CRLF $tmpSQLContent &= "CREATE TABLE [dbo].[Product]" & @CRLF $tmpSQLContent &= "(" & @CRLF $tmpSQLContent &= " [ProductId] [uniqueidentifier] DEFAULT NEWID() NOT NULL," & @CRLF $tmpSQLContent &= " [ProductName] [nchar](50) NULL," & @CRLF $tmpSQLContent &= " [ProductDescription] [nchar](3000) NULL," & @CRLF $tmpSQLContent &= " [ProductPrice] MONEY NULL" & @CRLF $tmpSQLContent &= ") ON [PRIMARY]" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "-- Table Sales" & @CRLF $tmpSQLContent &= "CREATE TABLE [dbo].[Sales]" & @CRLF $tmpSQLContent &= "( " & @CRLF $tmpSQLContent &= " [SaleId] [uniqueidentifier] DEFAULT NEWID() NOT NULL," & @CRLF $tmpSQLContent &= " [SaleName] [nchar](50) NULL," & @CRLF $tmpSQLContent &= " [SaleInfo] [nchar](3000) NULL," & @CRLF $tmpSQLContent &= " [SaleMoney] MONEY NULL" & @CRLF $tmpSQLContent &= ") ON [PRIMARY]" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "SET ANSI_NULLS ON" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "SET QUOTED_IDENTIFIER ON" & @CRLF $tmpSQLContent &= "GO" & @CRLF $tmpSQLContent &= "" & @CRLF $tmpSQLContent &= "-- The End" & @CRLF Local $hOpen = FileOpen($tmpSQLfile, 2 + 8 + 128) FileWrite($hOpen, $tmpSQLContent) Return FileClose($hOpen) EndFunc ;==>_SetTMPsql Func _OnExit() Exit FileDelete($tmpSQLfile) EndFunc ;==>_OnExit