0
votes

I'm having trouble getting RegExReplace to work correctly.

My input:

COW MOO OPTION:
test1|test2|test3||
test4|test5|test6||
CHICKEN WING:
test7|test8|test9|test10|test11|test12|test13|test14||test15||||test16|test17||
test18|test19|test20|||test21|test22|test23|test24|test25||

My RegExReplace: input := RegExReplace(input, "^(\w*\s?)*:$", "")

From my understanding this should remove text similar to COW MOO OPTION: or CHICKEN WING: however when I use MsgBox to view the input I still see the text.

I wish this type of text to be removed, how can this be done?

EDIT: I think I'm going to go with a Loop, Parse, on a newline.

inquiryRequest := clipboard
Loop, parse, inquiryRequest, `n
{
  if instr(A_LoopField, "|")
    result := result . A_LoopField . "`n"
}

But I'm still not sure why the RegExReplace didn't work?

1
Your regex itself seems fine. I tested it in my code editor and it finds both of your target strings. Maybe something about the way RegExReplace works? Try just using a very simple haystack and needle and see if the function really returns the value you expect. - SaganRitual
Can you provide an example with actual data you want to parse? Regex seems a bit overkill in this case. Here, you could just loop over each line and check if there's a :. Since you don't seem to be interested in the actual content of these "headlines", you certainly don't need to match them. Bottom line: If there won't be any colons in the list you're trying to retrieve, simly dismiss those which do contain one. - MCL
Addendum: This example shows what I meant. - MCL
@GreatBigBor, I'm not sure what you mean, inStr the resulting string? this still finds the colon. @MCL, I like your solution but I cannot say for sure that : won't be in the data and that's why I was thinking RegExReplace, but was hopping for a better way. - Lifeweaver

1 Answers

0
votes

I ended up using Loop Parse, in a similar way to what MCL suggested only instead of looking for :'s I looked for |'s since I know they will always been in a line I want.

inquiryRequest := clipboard
Loop, parse, inquiryRequest, `n
{
  if instr(A_LoopField, "|")
    result := result . A_LoopField . "`n"
}