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 matchingquery
substring followed 0+ characters other/
(see[^/]*
negated character class*
quantifier).*
- 0 or more characters to$
- end of string.
Comments
Post a Comment