Search the Community
Showing results for tags 'regexp pattern'.
-
I have a regular expression that I use in a StringRegExpReplace() function that replaces CRLFs if the matching text is the last text on a line. Here is my example script: test() Exit (1) Func test() Local $sfor, $pat, $sTextBefore = "", $sTextFixed $sTextBefore &= "Line 1 MF Midget vs NE Midget" & @CR $sTextBefore &= "Line 2 Midget 1 vs VYY Stars" & @CR $sfor = "Midget" $pat = "(?i)Midget\s{0,}[s]{0,1}\s{0,}[0-9]?+" $sTextFixed = StringRegExpReplace($sTextBefore, $pat, "+++") ConsoleWrite("+++: $pat ====>" & $pat & "<==" & @CRLF) ConsoleWrite("+++: $sTextBefore ==>" & @CRLF & $sTextBefore & @CRLF) ConsoleWrite("+++: $sTextFixed ===>" & @CRLF & $sTextFixed & @CRLF) EndFunc The output looks like this (I can't figure out how to remove the strikeout in this example):
-
I have got text file and I want to find two words with exact number of lines between them #include <Array.au3> ; first text $txt = '111' & @CRLF & '222' & @CRLF & '333' & @CRLF & '444' & @CRLF & '555' ; second text ;$txt = '111' & @CRLF & '222' & @CRLF & 'x' & @CRLF & 'y' & @CRLF & '333' & @CRLF & '444' & @CRLF & '555' $txt = StringRegExp($txt, '(?s)111(.*n{1,2}.*)333', 3) ;~ _ArrayDisplay($txt) For $i = 0 To UBound($txt) - 1 ConsoleWrite($i & ': ' & $txt[$i] & @CRLF) Next Here I try to find 111 and 333 and all between them but only in case when there are 1 or 2 @CRLF (rn) between them. So in first text it should find it and in second text (uncomment it) it shouldn't. But I'm not RegExp guru so my RegExp pattern is not OK and it finds my text no matter of number of @CRLFs. Of course I tried many combinations like (?s)111(.*)n{1,2}(.*)333 (?s)111.*n{1,2}.*333 (?s)111(.*rn{1,2}.*)333 ... but I need help from some RegExp guru with this ...