scala - Extract the word from String using Regex -
i have following
input:
abc_account2621_activity_20161116_20161117_030627_311999667.csv xyx_account2622_click_2016111606_20161116_221031_311735299.csv sed_account2623_impression_2016111605_20161116_221808_311685411.csv abc_account2621_rich_media_2016111606_20161116_192542_311735300.csv vbc_account2622_match_table_activity_cats_20161116_20161117_0311_31.csv.gz sbc_account2622_match_table_activity_types_20161116_20161117_0342_31.csv.gz
expected output
activity click impression rich_media match_table_activity_cats match_table_activity_types
code tried till now:
i want access word lies between [number + (-)underscore , end (-)underscore + number]
val x = "abc_account2621_match_table_activity_types_20161116_20161117_0342_31.csv.gz" val pattern3 = "(_([a-za-z]+_[0-9]))".r var word=pattern3.findfirstin(x).getorelse("no match") word: string = _types_2
val x = "abc_account2621_match_table_activity_types_20161116_20161117_0342_31.csv.gz" val pattern3 = """_([a-za-z_]+)_\d+""".r pattern3.findallin(x).matchdata.map(_.group(1)).tolist
_([a-za-z_]+)_\d+
matchdata
capture group
can capture this.
see regex101 this.
Comments
Post a Comment