Jump to content
Sign in to follow this  
PhoenixXL

StringRegExp General Help

Recommended Posts

PhoenixXL

Please don't double post in distinct threads

Sorry will keep in mind next time

PXL


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
PhoenixXL

The First Third and Sixth keypoint dont work

Please check the code for description

#region KeyPoints

;First : Double alphabets to single ['ll' to 'l']
;Second : Single vowels between words to none ['hello' to 'hllo']
;Third : in case of simultaneous vowels, delete the second one ['dissappointed' to 'dissapponted']
;Fourth : dont touch Single whole vowel [Like "I"]
;Fifth : dont touch vowel which is the starting of a word ['enjoy']
;Sixth : dont touch vowel which is the ending of a word ['made']

#endregion KeyPoints


Local $String = "Everytime when a message comes, I open just thinking its you.." & @CR & _
"When its not you, I don't get dissappointed!" & @CR & _
"Still I enjoy that moment which made me think of u! :)"

MsgBox(0, @ScriptName, ShortSentence($String))

Func ShortSentence($sString)
;Vowels Replacement
Local $sRegEx = StringRegExpReplace ( $sString, '([^aeiou ])([aeiou])([^aeiou ])*?', '13')
Return $sRegEx
EndFunc

Thanks for any possible help :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
PhoenixXL

any help ??


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
jchd

I'm not sure I can interpret your specifications correctly.

For instance how and in which order should rules apply in "aerial", "bacteria", "aqueous", "sequoia", "ian", "queueing", and the mouth-boggling word "euouae" (not that it's much common, but still).

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
PhoenixXL

"aerial" ==> Ignore first vowel and delete the second simultaneous vowel - aril

"bacteria" ==> Ignore the last vowel - bctra

"aqueous" ==> Ignore first vowel and delete second vowel [doesnt matter if more than two vowels are there] - aquous

"sequoia" ==> squia

"ian" ==> in

"queueing" ==> quueing

"euouae" ==> Ignore first and last vowel - euuae

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
jchd

Treatment of "aerial" and "ian" differs from "euouae".

Anyway I don't believe those rules can be made to work together in a single pattern: some apply repeatedly others only once.


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
PhoenixXL

Treatment of "aerial" and "ian" differs from "euouae".

No they are the same

aerial Ignore first vowel and delete the second simultaneous vowel - aril

ian Ignore the first vowel now left with only one vowel hence delete it - in

euouae Ignore first and last vowel then delete the second vowel - euuae

I don't believe those rules can be made to work together in a single pattern

Thnkx for the hint will try with multiple patterns Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
jchd

Ha, your first spec said "Don't touch" but this is "ignore it but don't ignore the fact that we're no more at the first char".

That explains 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)

Share this post


Link to post
Share on other sites
PhoenixXL

Done,

The shortened sentence now sounds well

CODE

#include-once

Opt('TrayIconDebug', 1)

#region -Index-
; Aim...........: To reduce the number of character in a sentence
; Description...: This Function deletes the vowels such that the sentences still sound the same
; Application...: Useful for texting(SMS) purposes through Internet
; Author........: Phoenix_XL
#endregion -Index-

#region -KeyPoints-
; Ignore the starting and ending vowels of any word

; Delete all the repeating consecutive alphabets[non-vowels] in a word
; -Excluding the last and first consecutive chars [if any]

; Remove all the single Vowels in b/w the word
; -In case of simultaneous vowels nothing is deleted

; Removes trailing WhiteSpaces
#endregion -KeyPoints-

#region -Example-
Local $String = ClipGet()
If @error Then Exit @error

ConsoleWrite('+===================================' & @CR)
ShortSentence($String)
ConsoleWrite('+===================================' & @CR)

ClipPut($String)
#endregion -Example-

; #FUNCTION# ====================================================================================================================
; Name ..........: ShortSentence
; Description ...: Trims the Vowels and Alphabets such that the phrase/sentence still sounds the same
; Syntax ........: ShortSentence(Byref $sString[, $fDebug = True])
; Parameters ....: $sString - [in/out] A string value. The String is modified
; $fDebug - [optional] A boolean value. Default is True.
; Return values .: Returns the Original String and @extended is to the number of replacements done
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func ShortSentence(ByRef $sString, $fDebug = True)
Local $aRegEx, $sBackUp = $sString, $iExt = 0
Local $sPattern = '(?i)([b-df-hj-np-tv-z])' & _ ; (First Group) Match the starting of the word with a consonant.
'([aeiou])([b-df-hj-np-tv-z]+)' ; (Second group & Third group) Matching the vowel and the following consonant(s).

$iExt += GeneralReplacements($sString)
;~ MsgBox ( 0, $iExt, $sString )

;Trim Repeating Non-Vowel Alphabets
$sString = StringRegExpReplace($sString, '(?i)(\B[b-df-hj-np-tv-z])(\1+\B)', '\1')
$iExt += @extended
;~ MsgBox ( 0, @extended, $sString )

;Set Extended for the Initiation
SetExtended(1)
While @extended
;~ MsgBox(0, $iExt, $sString)
$aRegEx = StringRegExpReplace($sString, $sPattern, '\1\3', 1)
$iExt += @extended - 1
;Assign the New String
$sString = $aRegEx
WEnd

;Remove the trailing space/
$sString = StringStripWS($sString, 2)
;Debug out
If $fDebug Then ConsoleWrite($sString & @CR)
;Completed
Return SetExtended($iExt, $sBackUp)

EndFunc ;==>ShortSentence

; #FUNCTION# ====================================================================================================================
; Name ..........: GeneralReplacements
; Description ...: Change some general words
; Syntax ........: GeneralReplacements(Byref $sString)
; Parameters ....: $sString - [in/out] A string value. The String is modified
; Return values .: Returns the number of replacements performed.
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func GeneralReplacements(ByRef $sString)
Local $aArray[9][2] = [["the", "d"],['eat|ate', '8'],['\band\b', 'n'],['good', 'gud'], _
['should', 'sud'],['one', '1'],['to|two', '2'],['we', 'v'],['because', 'bcoz']]
Local $iRet = 0
For $i = 0 To UBound($aArray) - 1
If $aArray[$i][0] = '' Then ContinueLoop
$sString = StringRegExpReplace($sString, '(?i)(' & $aArray[$i][0] & ')', $aArray[$i][1])
$iRet += @extended
Next
Return $iRet
EndFunc ;==>GeneralReplacements
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
PhoenixXL

How to match two same characters ?

The Help file says ddd Match character with octal code ddd, or backreference if found. Match the prior group number given exactly. For example, ([:alpha:])1 would match a double letter.

But the example is not working

#include <Array.au3>
$aRet = StringRegExp( 'Hello', '([:alpha:])1', 3 )
_ArrayDisplay( $aRet )

Thanks for any help


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
jchd

This is certainly the most common error wrt Posix character classes syntax.

Make it:

#include 
$aRet = StringRegExp( 'Hello', '([[:alpha:]])1', 3 )
_ArrayDisplay( $aRet )

[:alpha:] is an unbreakable single token inside a square-bracketed character class. Your pattern looked for any of : a l h p


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
PhoenixXL

thnks for the help :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
PhoenixXL

Again tried[previously

Example : Replaces Underscore with the following line

#include <Array.au3>


#region -Examples-
Local $sString
$sString = '$s = "This a short example."' & @CRLF & _
'ConsoleWrite($s & @LF)'
Display($sString, RegEx($sString))

$sString = '$s = "Another example." ; with a short comment _' & @CRLF & _
'ConsoleWrite($s & @LF)'
Display($sString, RegEx($sString))

$sString = '$s = "Yet another example _ ; tada."' & @CRLF & _
'ConsoleWrite($s & @LF)'
Display($sString, RegEx($sString))

$sString = 'DllCall("ntdll.dll", "int", "RtlCompressBuffer", _' & @LF & _
'"ushort", 2, _ ;------> CompressFormat' & @LF & _
'"ptr", $pInput, _ ;---> ptrSrceBuffer' & @LF & _
'"dword", $iSize, _ ;--> SrceBufferSize' & @LF & _
'"ptr", $pBuffer, _ ;--> ptrDestBuffer' & @LF & _
'"dword", $iBufLen, _;aa; vv;> DestBufferSize' & @LF & _
'"dword", 4096, _ ;----> ChunkSize' & @LF & _
'"dword*", 0, _ ;------> CompressedSize' & @LF & _
'"ptr", $pWrkSp) ;-----> WorkspaceBuffer'
Display($sString, RegEx($sString))

$sString = 'MsgBox(4096, "Title _ v1", "This program is free software: you can redistribute it and/or modify" & _' & @LF
$sString &= ' "it under the terms of the GNU General Public License " _" & _ ; Only comment!' & @LF
$sString &= ' "as published by the Free Software Foundation, either version 3" & _' & @LF
$sString &= ' "of the License, or (at your option) any later version.")' & @LF
$sString &= '$aRtl = DllCall("ntdll.dll", "int", "RtlCompressBuffer", _' & @LF
$sString &= ' "ushort", 2, _ ;------> CompressFormat' & @LF
$sString &= ' "ptr", $pInput, _ ;---> ptrSrceBuffer' & @LF
$sString &= ' "dword", $iSize, _ ;--> SrceBufferSize' & @LF
$sString &= ' "ptr", $pBuffer, _ ;--> ptrDestBuffer' & @LF
$sString &= ' "dword", $iBufLen, _ ;> DestBufferSize' & @LF
$sString &= ' "dword", 4096, _ ;----> ChunkSize' & @LF
$sString &= ' "dword*", 0, _ ;------> CompressedSize' & @LF
$sString &= ' "ptr", $pWrkSp) ;-----> WorkspaceBuffer' & @LF
$sString &= '_ ; Only comment!'
Display($sString, RegEx($sString))
#endregion -Examples-


Func RegEx($sString)
Local $aRet = ''
;Get Each Line
$aArray = StringRegExp($sString, '(?m)([^\r\n]+)(?:[\r\n]+|$)', 3)
;_ArrayDisplay( $aArray )
For $a = 0 To UBound($aArray) - 1
$aRet &= CheckUnderScore($aArray[$a])
;~  StringRegExpReplace( $sString, '(?s)(?x)([''"])(.*?1)([()><=+-/*,[:digit:]]?)*', '')
Next
If @error Then Return SetError(1, @error, -1)
Return $aRet
EndFunc   ;==>RegEx

Func CheckUnderScore($sString)
Local $aRet, $Comment = False
;Replace the Quotes
$aRet = StringRegExpReplace($sString, '(?s)([''"])(.*?\1)', '')
;Number of Semi-Colon in comments
StringRegExpReplace($aRet, ';', '')
$Comment = @extended
;Replace the Comments
$aRet = StringRegExpReplace($aRet, '(?m)(;.*)(\r\n|$|\r|\n)', '')

;~ MsgBox(0, $Comment, $aRet)

;Remove Trailing Spaces
$aRet = StringStripWS($aRet, 2)

;Done
If StringRight($aRet, 1) = '_' Then
;Check Comments
If $Comment Then
$sString = StringMid($sString, 1, StringInStr($sString, ';', 2, $Comment * - 1) - 1)
;~ $sString = StringRegExpReplace($sString, '(?s)(.*?)(;.*)+', '1')
;~ MsgBox(0, 0, $sString)
Else
;And replace them
$sString = StringReplace($sString, @CR, '')
$sString = StringReplace($sString, @LF, '')
EndIf
;Underscore Replace
$sString = StringReplace($sString, '_', '', -1)
EndIf
Return $sString

EndFunc   ;==>CheckUnderScore

Func Display($sInput, $sOutput)
;Display the Result
ConsoleWrite(StringFormat('>Input: %s\n+Output: %s\n\n', $sInput, $sOutput))
EndFunc   ;==>Display

Please try it and

i would be very grateful,

If someone finds a fault in it :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
PhoenixXL

Anyone tried the example ?

Please give me feedback


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
PhoenixXL

Made some StringOpearations using RegEx

Hope so someone finds it helpful :)

#include-once
#include <Array.au3>

#cs
trying to make some string functions
using Regular Expressions
will add some more soon
#ce

; #CURRENT# =====================================================================================================================
; RegEx_StringLeft
; RegEx_StringLen
; RegEx_StringLower
; RegEx_StringMid
; RegEx_StringRepeat
; RegEx_StringReplace
; RegEx_StringReverse
; RegEx_StringRight
; RegEx_StringTrimLeft
; RegEx_StringTrimRight
; RegEx_StringUpper
; ===============================================================================================================================

; #INTERNAL_USE_ONLY# ===========================================================================================================
; CheckPattern
; ===============================================================================================================================


; #FUNCTION# ====================================================================================================================
; Name ..........: RegEx_StringReplace
; Description ...: Similar to StringReplace
; Syntax ........: RegEx_StringReplace($sString, $sSearch, $sReplace[, $iInSensitive = 1[, $iOccurrence = 0[, $iContinue = False[,
;                  $iRegEx = False]]]])
; Parameters ....: $sString             - A string value.
;                  $sSearch             - A string value.
;                  $sReplace            - A string value.
;                  $iInSensitive[1]     - [optional] An integer value.
;                  $iOccurrence[0]      - [optional] An integer value.
;                  $iContinue[False]    - [optional] Will Replace Continuously till the Occurrence[inclusive]
;                  $iRegEx[False]       - [optional] Signifies that the Search and Replace terms are Regular Expressions
; Return values .: Returns the String with @extended set to the number of replacements
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......: Havent added any Error Check
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func RegEx_StringReplace($sString, $sSearch, $sReplace, $iInSensitive = 1, $iOccurrence = 0, $iContinue = False, $iRegEx = False)
Local $iReverse = False
;Insensitiveness
If $iInSensitive Then
$iInSensitive = '(?i)'
Else
$iInSensitive = ''
EndIf
If $iOccurrence < 0 Then
;Check for Negative occurance
$iReverse = True
$iOccurrence *= -1
$sString = RegEx_StringReverse($sString)
EndIf
;Check for special characters
If Not $iRegEx Then
CheckPattern( $sSearch )
If ($iOccurrence - 1) And Not $iContinue Then
$sSearch = '(?s)' & $sSearch & '((.*?)(\1)){' & $iOccurrence - 1 & '}'
$sReplace = '\1\3' & $sReplace
EndIf
EndIf
;main function
Local $aRet = StringRegExpReplace($sString, $iInSensitive & $sSearch , $sReplace, $iOccurrence)
Local $iExt = @extended
If Not $iContinue Then $iExt = 1
If $iReverse Then $aRet = RegEx_StringReverse($sString)
Return SetExtended($iExt, $aRet)
EndFunc ;==>RegEx_StringReplace

; #FUNCTION# ====================================================================================================================
; Name ..........: RegEx_StringMid
; Description ...: Extract a number of characters from the string
; Syntax ........: RegEx_StringMid($sString[, $iStart = 0[, $iEnd = 0]])
; Parameters ....: $sString - A string value.
; $iStart - [optional] An integer value. Default is 0.
; $iEnd - [optional] An integer value. Default is 0.
; Return values .: Failure - Sets @error to non-zero and returns the whole string
; Success - Returns the new stirng
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func RegEx_StringMid($sString, $iStart = 0, $iEnd = 0) ;First Char = 0
;If Start and End are 0 then Return the whole string
If Not BitOR($iStart, $iEnd) Then Return $sString
;If Out of Bounds then Return
If $iStart + $iEnd > RegEx_StringLen($sString) Then Return SetError(1, 0, $sString)
If $iStart > RegEx_StringLen($sString) Then Return SetError(2, 0, $sString)
If $iEnd < 0 Then Return SetError(3, 0, $sString)
If $iStart < 0 Then Return SetError(4, 0, $sString)
;Carry Out the Main Function
If $iStart Then $sString = StringRegExpReplace($sString, '(?s)(.{' & $iStart & '})', '', 1)
If $iEnd Then $sString = StringRegExpReplace($sString, '(?s)(.{' & $iEnd & '})(.*)', '\1', 1)
Return $sString
EndFunc ;==>RegEx_StringMid


; #FUNCTION# ====================================================================================================================
; Name ..........: RegEx_StringReverse
; Description ...: Reverses the String
; Syntax ........: RegEx_StringReverse($sString[, $iStart = 0[, $iEnd = 0]])
; Parameters ....: $sString - A string value.
; $iStart - [optional] An integer value. Default is 0.
; $iEnd - [optional] An integer value. Default is 0.
; Return values .: Returns the reversed string
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func RegEx_StringReverse($sString, $iStart = 0, $iEnd = 0)
Local $sStart = '', $sEnd = ''
;Get the Start which would not be reversed
If $iStart > 0 Then $sStart = RegEx_StringMid($sString, 0, $iStart)
;Get the Start which would not be reversed
If $iStart + $iEnd < RegEx_StringLen($sString) Then $sEnd = RegEx_StringMid($sString, RegEx_StringLen($sString) - ($iStart + $iEnd))
;The Original String which has to be reversed
$sString = RegEx_StringMid($sString, $iStart, $iEnd)
;main function
Local $aRet = StringRegExp($sString, '(?s)(.)', 3)
_ArrayReverse($aRet)
Return $sStart & _ArrayToString($aRet, '') & $sEnd
EndFunc ;==>RegEx_StringReverse

; #FUNCTION# ====================================================================================================================
; Name ..........: RegEx_StringLen
; Description ...: Get the Length of the String
; Syntax ........: RegEx_StringLen($sString)
; Parameters ....: $sString - A string value.
; Return values .: Length of the String
; Author ........: Your Name
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func RegEx_StringLen($sString)
;Replace Each Character
StringRegExpReplace($sString, '(?s)(.)', '')
;Return the Number of replacements
Return @extended
EndFunc ;==>RegEx_StringLen

; #FUNCTION# ====================================================================================================================
; Name ..........: RegEx_StringRepeat
; Description ...: Repeats the String
; Syntax ........: RegEx_StringRepeat($sString, $iTimes)
; Parameters ....: $sString - A string value.
; $iTimes - An integer value.
; Return values .: Returns the new string
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func RegEx_StringRepeat($sString, $iTimes)
Local $_ReplaceString
;make the replace string
For $i = 1 To $iTimes
$_ReplaceString &= '\1'
Next
;Return
Return StringRegExpReplace($sString, '(?s)(.*)', $_ReplaceString)
EndFunc ;==>RegEx_StringRepeat

; #FUNCTION# ====================================================================================================================
; Name ..........: RegEx_StringLeft
; Description ...: Extract Characters from the Left
; Syntax ........: RegEx_StringLeft($sString, $iCount)
; Parameters ....: $sString - A string value.
; $iCount - An integer value.
; Return values .: The extracted string
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func RegEx_StringLeft($sString, $iCount)
Return RegEx_StringMid($sString, 0, $iCount)
EndFunc ;==>RegEx_StringLeft

; #FUNCTION# ====================================================================================================================
; Name ..........: RegEx_StringRight
; Description ...: Extract Characters from the Right
; Syntax ........: RegEx_StringRight($sString, $iCount)
; Parameters ....: $sString - A string value.
; $iCount - An integer value.
; Return values .: The extracted string
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func RegEx_StringRight($sString, $iCount)
Return RegEx_StringReverse(RegEx_StringLeft(RegEx_StringReverse($sString), $iCount))
EndFunc ;==>RegEx_StringRight

; #FUNCTION# ====================================================================================================================
; Name ..........: RegEx_StringTrimLeft
; Description ...: Strip a number of char from the left
; Syntax ........: RegEx_StringTrimLeft($sString, $iCount)
; Parameters ....: $sString - A string value.
; $iCount - An integer value.
; Return values .: The New String
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func RegEx_StringTrimLeft($sString, $iCount)
Return RegEx_StringRight($sString, RegEx_StringLen($sString) - $iCount)
EndFunc ;==>RegEx_StringTrimLeft

; #FUNCTION# ====================================================================================================================
; Name ..........: RegEx_StringTrimRight
; Description ...: Strip a number of char from the right
; Syntax ........: RegEx_StringTrimRight($sString, $iCount)
; Parameters ....: $sString - A string value.
; $iCount - An integer value.
; Return values .: The New String
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func RegEx_StringTrimRight($sString, $iCount)
Return RegEx_StringLeft($sString, RegEx_StringLen($sString) - $iCount)
EndFunc ;==>RegEx_StringTrimRight

; #FUNCTION# ====================================================================================================================
; Name ..........: RegEx_StringLower
; Description ...: Convert UpperCase to LowerCase
; Syntax ........: RegEx_StringLower($sString)
; Parameters ....: $sString - A string value.
; Return values .: The New String
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func RegEx_StringLower($sString)
Local $iOff = 0
For $i = 101 To 132
$sString = StringRegExpReplace($sString, '\' & $i + $iOff, ChrW($i - 103 + 97))
If RegEx_StringRight($i,1) = '7' Then $iOff += 2
Next
Return $sString
EndFunc ;==>RegEx_StringLower

; #FUNCTION# ====================================================================================================================
; Name ..........: RegEx_StringUpper
; Description ...: Convert Lower Case to UpperCase
; Syntax ........: RegEx_StringUpper($sString)
; Parameters ....: $sString - A string value.
; Return values .: The New String
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func RegEx_StringUpper($sString)
Local $iOff = 0
For $i = 141 To 172
$sString = StringRegExpReplace($sString, '\' & $i + $iOff, ChrW($i - 141 + 65))
If RegEx_StringRight($i,1) = '7' Then $iOff += 2
Next
Return $sString
EndFunc ;==>RegEx_StringLower

; #INTERNAL USE ONLY# ===========================================================================================================
; Name ..........: CheckPattern
; Description ...: Checks the Parameter of a RegExp
; Syntax ........: CheckPattern (Byref $sString)
; Parameters ....: $sString - [in/out] A string value.
; Return values .: Always returns 1
; Author ........: Phoenix XL
; Modified ......:
; Remarks .......: The Search String can also include Special characters that would disrupt
; the Regexp therefore this function encloses each character in sets.
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func CheckPattern (ByRef $sString )
;enclose withing sets so that special character lose their meaning
$sString = '(' & StringRegExpReplace ( $sString, '(?s)(.)', '[\1]' ) & ')'
Return 1
EndFunc

Edit : Added Documentation

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
FireFox

Hi,

I would like to know how to do this (in regexp of course) :

I have an url and some parameters need to be removed (with their value), they can begin by "?" or "&" and they can end by "&" or nothing, but it's important to check before for the "&" instead of the "nothing"

$s = "?t1=toto&t2=titi&t3=tyty&t4=tutu"
;if I want to remove t1, t3 & t4 the result will be :
?t2=titi
;note that the "?" need to stay, whereas the "&" needs to be removed.

Anyhelp will be much appreciated.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
jdelaney

#include <Array.au3>
$s = "?t1=toto&t2=titi&t3=tyty&t4=tutu"
$a = StringRegExp ( $s, "(??[w=]+)&?", 3)
_ArrayDisplay ( $a)

note, that html is stripping the '=' right after the , after the w

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
FireFox

Thanks!

You made a little mistake with a before the ].

Is there a solution with the regexpreplace to directly get the replaced string?

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
FireFox

that wasn't a mistake :)...look at my 'note'

hm ok you meant the forum strip it.

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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  

×