Home > Enterprise >  Scala: extracting part of a file path
Scala: extracting part of a file path

Time:11-08

I'm using scala and trying to extract the value from the path, for ex.:

val path = hdfs://aloha/data/8907yhb/folders/folder=2319/

please would you tell me what regex can I use for [extracting part]

I have tried it at https://regexr.com/

[I've tried different expressions]

(https://i.stack.imgur.com/pvgVX.png)

"=[0-9]*" 

I didn't get exactly what I expect.

The best result I got:

=2319 

but I need to get only

2319

CodePudding user response:

You can use look behind (?<=...) pattern.

(?<==)[0-9]* // matches zero or more digits but only if they follow the '=' sign.

Example:

scala> "(?<==)[0-9]*".r.findAllIn("hdfs://aloha/data/8907yhb/folders/folder=2319/").toList

List(2319)


  • Related