-2

I have different paths in a column like below:

'E:/R_Process/R_Input_UDM//Greater Europe/CEW Hub/Austria/Toothpaste/Variant Data/AUSTRIA_SHG_VARIANT_8.csv'
'E:/R_Process/R_Input_UDM//Greater Europe/CEW Hub/Austria/ManualTB/Variant Data/AUSTRIA_SHG_VARIANT_7.csv'
'E:/R_Process/R_Input_UDM//Greater Europe/CEW Hub/Austria/MouthWash/Variant Data/AUSTRIA_SHG_VARIANT_9.csv'

I want Toothpaste from 1st path, ManualTB from 2nd, and MouthWash from 3rd.

There are many more paths around 30 every from every paths I want the word from 7th slash.

How can I do this using regex?

Richard
  • 106,783
  • 21
  • 203
  • 265

2 Answers2

0

You can use the following regex:

(?:\/([^\/\n]*)){7}

Check Regex Demo

Required keywords would be in capture group 1

karthik manchala
  • 13,492
  • 1
  • 31
  • 55
0

You can match any optional characters followed by a slash and capture the word following it by using this regex,

(?:.*?\/){7}(\w+)

Explanation:

  • (?:.*?\/){7} --> Non capture group matching any optional characters followed by / seven times
  • (\w+) --> Capture the following word in group 1

Demo

Let me know if this works fine for you.

Pushpesh Kumar Rajwanshi
  • 18,127
  • 2
  • 19
  • 36