0

I have the following string:

   uri=/abc/jkncedknj/dslkmfldsmf/245?X_Security_Token=o93457yndo49758yewrwet&accountId=bob123

I want to essentially obfuscate the x_secuirty_token, so essentially delete all but 4 characters in the string: o93457yndo49758yewrwet

Currently I'm following these steps to achieve it:

  • find the token within the string
  • extract it from the string
  • get the first four digits of the token and place it back in the string

The strings are dynamic so I'm essentially looking into replacing anything from the = after the X_Security_Token to &accountId=bob123

I've tried the following:

[Token][=]{a-zA-z0-9}+[&accountId] but it's complaining that the syntax would be incorrect. I've tried other variations but it still doesn't work. I'm pretty new to regex.

monamona
  • 1,195
  • 2
  • 17
  • 43
bootlover123
  • 111
  • 1
  • 8
  • You just use `X_Security_Token=[^&]*` to match the query param with its value. `[&accountId]` matches a single char, either `&`, or `a`, or `c`, or `u`... and `{a-zA-z0-9}` is a completely messed part that should have been written as `[a-zA-Z0-9]` – Wiktor Stribiżew Oct 15 '20 at 11:36
  • Thanks for this. The `X_Security_Token=[^&]*` captures the following: `X_Security_Token=o93457yndo49758yewrwet`. I jsut want `o93457yndo49758yewrwet`. Any ideas? – bootlover123 Oct 15 '20 at 11:51
  • Sure, capture it, `X_Security_Token=([^&]*)` and grab Group 1 value. Or use a lookbehind, `(?<=X_Security_Token=)[^&]*` – Wiktor Stribiżew Oct 15 '20 at 11:54

0 Answers0