regex - Remove part of string before last "/" -


i want remove before /query .. e.g

i have no idea regular expressions doing difficult me

note : reference should /query link mentioned below may have different patterns - www.abcd.wsd/asd/asdcd/asrr/query=xyz

www.html.com/query=abcd

should result

 query = abcd 

a generic regex solution extract query appearing after last / , followed characters other / is

s <- c("www.abcd.wsd/asd/asdcd/asrr/query=xyz","www.html.com/query=abcd","www.cmpnt.com/query=fgh/noquery=dd") sub("^.*/(query[^/]*).*$", "\\1", s) ## => "query=xyz"  "query=abcd" "query=fgh" 

see this r demo

the regex is

^.*/(query[^/]*).*$ 

see regex demo

details:

  • ^ - start of string
  • .* - match 0+ characters many possible last
  • / - literal forward slash char
  • (query[^/]*) - capture group 1 matching query substring followed 0+ characters other / (see [^/]* negated character class * quantifier)
  • .* - 0 or more characters to
  • $ - end of string.

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -