regex - Scala: How to always extract the same substring out from strings with different prefix and/or suffix -


given following strings...

val s0 = "objects" val s1 = "/objects" val s2 = "/objects(0)" val s3 = "/objects(1)" 

i need extract substring objects, regardless of possible prefix , suffix. if string started slash , ended (n), easiest solution be

scala> s3.substring(1).substring(0, s3.indexof("(") - 1) res1: string = objects 

how extract string objects regex (i suppose way go)?

you use below regex , string want group index 1.

^\/?(.*?)(?=(?:\(\d*\))?$) 

demo


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -