0
votes

Using Autohotkey, I need to exclude a part of a string, while still writing the first and last part of it. I'll explain. Given the String:

GSM NWS\TOP N Pool 1\1. TOP N Pool 1 Rank :

GSM NWS\TOP N Pool 1\1. TOP N Pool 1 BCCH :

GSM NWS\TOP N Pool 1\1. TOP N Pool 1 BSIC :

I Need to extract only the parts from "1." until ":", excluding the "TOP N Pool 1" part. Thus, the wanted string should be:

  1. Rank
  2. BCCH
  3. BSIC

I've been around this question for quite a while now, and I've used RegExMatch:

RegExMatch(A_LoopField,  "\d+\.(.*?)\[\d\]", fields%lineCount%)

This RegEx is not excluding that middle string I want to leave out.

Any ideas?

P.S: I'm relatively new to this language, and to the Regular Expression usage as well...please forgive if i'm making any basic mistake here.

Thank you all.

1
There are many ways to match the data you need. You have to be specific on what is variable, what is fixed, optional (etc..), the type of text you want to grab, Otherwise it's a guessing game .. - user557597

1 Answers

0
votes

You can use capturing groups, like in regex:

(\d\.).+\d\s(\w+)\s:

parts in parentheses capture text, which you can use afterward, using $1,$2, etc. Here $1 is for (\d\.) which captures for example: 1. , and $2 for (\w+) which should capture Rank. So I suppose (as I don't have a background in AHK) you should be able to do something like:

NewStr := RegExReplace("GSM NWS\TOP N Pool 1\1. TOP N Pool 1 Rank :", "(\d\.).+\d\s(\w+)\s:", "$1$2")

and the result should be: 1.Rank

Look here how regex works: DEMO