简体   繁体   中英

Autohotkey regex exclude part of string

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?

PS: 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM