使用VIM Regex在两个关键字之间查找文本

时间:2015-07-27 18:24:05

标签: regex vim regex-lookarounds vim-syntax-highlighting

我正在尝试在Vim中配置语法突出显示。使用正则表达式我无法找到两个字符序列之间的字符。

序列是:

import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.collection.mutable.ListBuffer
import util.Random.nextInt
import java.io.IOException
import java.io.FileWriter;

object HelloWorld {
    def main(args: Array[String]) {

    val p1=1<<56
    val p2=7<<52
    val p3=0<<32

    val r = scala.util.Random   

    val fw = new FileWriter("steam_out_scala.txt", true)

for (i <- 0 to 3) {

    val thread = new Thread {
        override def run {
            val p4=r.nextInt(1000000)
            val url=("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXYYYZZZ,steamids="+((p1|p2)|(p3|p4))).toString

            try{
            val in = scala.io.Source.fromURL(url.toString,"utf-8")
            fw.write(((p1|p2)|(p3|p4)).toString)
            //fw.close()
            }
            catch{
                case e: IOException => { //catches api call fail AND file write failed
                    println("failed for num: "+(((p1|p2)|(p3|p4)).toString))
                }
            }
        }
    }
    thread.start
    //Thread.sleep(50)
}
fw.close() //moved here
}}

我想抓住例如facebook&sdk_version=7.2.3&appid=34428&language=en_AR&screen_height=1136&app_version=7.2.3&apple_idfa "sdk_version="之间的部分。含义"&appid="

有什么想法吗?

2 个答案:

答案 0 :(得分:3)

这样的事情怎么样:

sdk_version=\zs\d\+\.\d\+\.\d\+

\zs之前的所有内容都需要匹配,但不会被视为 匹配的一部分。

然后你的实际匹配将是三个数字,用点分隔。

另一种选择是在“sdk_version =&#39;之后抓住所有内容。直到下一个&符号:

sdk_version=\zs[^&]*

答案 1 :(得分:0)

匹配所有值:

df_eq.end=df_eq.end.fillna(pd.to_datetime(datetime.date.today()))

def days_in_year(start,end,year):
    start_of_year=pd.to_datetime(datetime.date(year,1,1))
    end_of_year=pd.to_datetime(datetime.date(year,12,31))
    if start.year>year or end.year<year:
        return 0
    initial_date=start_of_year if start_of_year>start else start
    ending_date=end_of_year if end_of_year<end else end
    return (ending_date-initial_date+pd.Timedelta(days=1))/(end_of_year-start_of_year+pd.Timedelta(days=1))

df_inv_yr=pd.DataFrame(np.asarray(map(lambda year: map(lambda srt, end: days_in_year(srt,end,year), df_eq.start,df_eq.end),[2011,2012,2013,2014])).T.tolist(),columns=[2011,2012,2013,2014])

first_sample_output=pd.concat([df_eq,df_inv_yr],axis=1).groupby(['char1'])[[2011,2012,2013,2014]].sum().reset_index()

second_sample_output=pd.concat([df_eq,df_inv_yr],axis=1).groupby(['char1','char2'])[[2011,2012,2013,2014]].sum().reset_index()

=\zs[^&]\+\ze&

(第一个RE要求在最后一个值之后有=\zs[^&]\+ ,即最后一个组件必须是无值属性,如示例所示。)

两种变体都禁止空值:由于目的是突出显示,我认为空值不是很有趣。将&替换为*以允许它们。