-1

I want to remove jsessionid from given string url and backslash @start

/product.screen?productId=BS-AG-G09&JSESSIONID=SD1SL6FF6ADFF6510

so that output would be like

product.screen?productId=BS-AG-G09

More data like :

1                      /product.screen?productId=WC-SH-A02&JSESSIONID=SD0SL6FF7ADFF4953
2                                     /oldlink?itemId=EST-6&JSESSIONID=SD0SL6FF7ADFF4953
3                       /product.screen?productId=BS-AG-G09&JSESSIONID=SD0SL6FF7ADFF4953
4                       /product.screen?productId=FS-SG-G03&JSESSIONID=SD0SL6FF7ADFF4953
5  /cart.do?action=remove&itemId=EST-11&productId=WC-SH-A01&JSESSIONID=SD0SL6FF7ADFF4953
6                                    /oldlink?itemId=EST-14&JSESSIONID=SD0SL6FF7ADFF4953
7     /cart.do?action=view&itemId=EST-6&productId=MB-AG-T01&JSESSIONID=SD1SL6FF6ADFF6510
8                       /product.screen?productId=BS-AG-G09&JSESSIONID=SD1SL6FF6ADFF6510
9                       /product.screen?productId=WC-SH-A02&JSESSIONID=SD1SL6FF6ADFF6510
10    /cart.do?action=view&itemId=EST-6&productId=WC-SH-A02&JSESSIONID=SD1SL6FF6ADFF6510
11                      /product.screen?productId=WC-SH-A02&JSESSIONID=SD1SL6FF6ADFF6510
Axeman
  • 32,068
  • 8
  • 81
  • 94
SumitArya
  • 111
  • 5
  • Possible duplicate of [R remove part of string](https://stackoverflow.com/questions/9704213/r-remove-part-of-string) – Koot6133 Oct 05 '17 at 14:32
  • Please provide an actual dataset with the specific column whose values you're trying to clean up. – Abdou Oct 05 '17 at 15:03

1 Answers1

0

You may use:

library(stringi)

lf1 = "/product.screen?productId=BS-AG-G09&JSESSIONID=SD0SL6FF7ADFF4953"

stri_replace_all_regex(
"/product.screen?productId=BS-AG-G09&JSESSIONID=SD0SL6FF7ADFF4953",
"&JSESSIONID=.*","")

Where the string: &JSESSIONID=.* (up to the end .*) gets replaced with nothing ("").

or simply: gsub("&JSESSIONID=.*","",lf1)

aatrujillob
  • 4,738
  • 3
  • 19
  • 32
  • `lf2 = stri_replace_all_regex(lf$request_url,"&JSESSIONID=.*","") lf3 = lf %>% mutate(request = lf2)` where **lf** is origional dataframe .This is working but taking 2 extra steps .what would be easier way.I just want to remove that session ids and keep url in origional **lf** dataframe – SumitArya Oct 05 '17 at 15:03