Jump to content

Regex expression problem


Travis
 Share

Recommended Posts

I have a problem here with Regex,

If I were to use this expression

$arr = StringRegExp("STARTblablablaaENDblabSTARTlabENDlabSTARTblablaEND","START([a-z|A-Z]*)END",3)

Regex will return only one match, which will contain everything between the first "START" and the last "END"

I do not know how (if it is possible) to tell regex what I know: That between "START" and "END" there will never be the phrase "START" or "END"! but it doesn't know that, because it's only matching any alphabetical character.....

I need to return an array that would have each match separate like this: "blablablaa", "lab", "blabla".

The above expression was just an example, in my actual string it would be all uppercase. But I have tested this above expression and it performs exactly as my program does... Is there any possible way to tell it to match everything except a certain phrase?

Link to comment
Share on other sites

Isnt a replace better at such a condition

#include <Array.au3>

$arr = StringRegExpReplace("STARTblablablaaENDblabSTARTlabENDlabSTARTblablaEND","START|END","")

ConsoleWrite( $arr & @CR )

Are you doing it for nesting purpose,

bcoz i had recently made an Regex for Nesting

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.

Link to comment
Share on other sites

A lazy operator may help

#include <Array.au3>

$String = "STARTRegularExpEND^^^^STARTHelpEND not to capture STARTsomemorecharsEND"
;Need to extrac "

$Ret_arr = StringRegExp( $String,"START([[:alpha:]]*?)END",3)

_ArrayDisplay( $Ret_arr )

Regards :)

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.

Link to comment
Share on other sites

This example makes use of the lookahead and lookbehind assertions.

#include <Array.au3>

Local $sTestString = "STARTRegularExpEnd^^^^StartHelpENDAlso able to be captured.START Some more chars END"

; This Reg. Exp. pattern matches that which is ahead of START and is behind END.
Local $aArrayBetweenStart_EndOnly = StringRegExp($sTestString, "(?i)(?<=START).+?(?=END)", 3)
_ArrayDisplay($aArrayBetweenStart_EndOnly, "Between START and END Only")

; This Reg. Exp. pattern matches that which is ahead of START and is behind END, or,
; matches that which is ahead of END and is behind START.
; "Start" and "End" can be upper or lower case because of "(?i)" in the pattern.
Local $aArrayBetweenAllStarts_Ends = StringRegExp($sTestString, "(?i)(?<=START).+?(?=END)|(?<=End).+?(?=START)", 3)
_ArrayDisplay($aArrayBetweenAllStarts_Ends, "Between All STARTs and ENDs")
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...