B4J Question How To Regex This Text


Well-Known Member
Licensed User
Can someone show me the regex to split each line of the following text into a three-member string array split by the '=' and ':'?

James Bond=2558963298:C215712
Kevin Costner=1855544359:C225971
Milla Jovovich=788300210:C225043
Paul Simon=2758362877:C216819
Old McDonald=1888642090:C215545
Marcus Aurelius=1523664491:C223065


Well-Known Member
Licensed User
ANSWERED! Found here.

Using Regex.Split("=|:",my_text) for each line does the work.

Let me know if there's a better way! (I've seen a reference to MULTI_LINE, so maybe I don't have to read each line of the file...)
Upvote 0


Well-Known Member
Licensed User
Longtime User
don't be "ascairt", try it. you'll see how it treats your multiline string.

 dim text as string = file.readstring( your_file )
to read in your file,

then apply your constraint
 Dim splitter As List = Regex.Split2( "=:", Regex.MULTILINE, text)

then step through your splitter to see what you got.

it might look the same as before at first glance, but it's not. you'll have to look closely to see why. the MULTILINE constraint essentially treats your list of "records" as a 1-line string (which it isn't). that's the purpose of the constraint. when you use MULTILINE, you're basically saying, "i know we're looking at a bunch of discrete strings (separated by CRLF), but i want you to ignore that, and make like it's just one big string." this screws with the regex splitter because it makes the beginning of the "next" string appear like part of the "last" string. the CRLF is needed to divide each "record" into 3 elements.

you would use MULTILINE, for example, if you're scraping a web page looking for something. let's say you're looking for 2 particular words in succession. well, if word 1 appears on one line and word 2 appears on the next line, regex won't find the match. you need to search for the words using the MULTILINE constraint.
Upvote 0