Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. Exclude already masked data in regex

Exclude already masked data in regex

Scheduled Pinned Locked Moved Regular Expressions
regexhelptutorialquestion
3 Posts 2 Posters 24 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NathanAsh
    wrote on last edited by
    #1

    hi I am trying to mask 3 to 8 digit numbers alone exclusively, by excluding already masked data with another regex pattern. For example it should not match the masked patterns like [xX\-\*\d{1,4}] , but match the pattern \d{3,8} Can you please help with the regex pattern to achieve this? I have tried something like this, but its not matching for the pattern \d{3,8}

    (?<=(?

    Input :

    1234
    x123412345678
    -123412345678
    *123412345678
    123
    1234
    12345
    123456
    1234567
    12345678

    Expected masking

    ****
    x1234****
    -1234****
    *1234****
    ****
    ****
    ****
    ****
    ****
    ****

    T 1 Reply Last reply
    0
    • N NathanAsh

      hi I am trying to mask 3 to 8 digit numbers alone exclusively, by excluding already masked data with another regex pattern. For example it should not match the masked patterns like [xX\-\*\d{1,4}] , but match the pattern \d{3,8} Can you please help with the regex pattern to achieve this? I have tried something like this, but its not matching for the pattern \d{3,8}

      (?<=(?

      Input :

      1234
      x123412345678
      -123412345678
      *123412345678
      123
      1234
      12345
      123456
      1234567
      12345678

      Expected masking

      ****
      x1234****
      -1234****
      *1234****
      ****
      ****
      ****
      ****
      ****
      ****

      T Offline
      T Offline
      Terry R 2023
      wrote on last edited by
      #2

      If I were to use Notepad++ then the find regex would be:

      ([x\-*]\d{1,4})?(\d{3,8})

      So it ties the 1-4 numbers immediately following a x (or X as Notepad++ normally case insensitive), a - (this is a meta character so needs the escape char to make it a normal char) or a *. Having them in a group with a ? allows for non capture if the line doesn't start with the x, - or *. The second group captures between 3 and 8 numbers. Now this all works as expected in Notepad++, however sometimes these don't translate well across the various regular expression engines. As you haven't provided that info I can't give you an answer specific to your need. Also I note you seem to want to "mask" the 3-8 digits. As it stands my 2nd group will just support replacing with a fixed number of "*", so some adjustment would be needed. Hopefully this has helped you though to continue with a final solution. Terry

      N 1 Reply Last reply
      0
      • T Terry R 2023

        If I were to use Notepad++ then the find regex would be:

        ([x\-*]\d{1,4})?(\d{3,8})

        So it ties the 1-4 numbers immediately following a x (or X as Notepad++ normally case insensitive), a - (this is a meta character so needs the escape char to make it a normal char) or a *. Having them in a group with a ? allows for non capture if the line doesn't start with the x, - or *. The second group captures between 3 and 8 numbers. Now this all works as expected in Notepad++, however sometimes these don't translate well across the various regular expression engines. As you haven't provided that info I can't give you an answer specific to your need. Also I note you seem to want to "mask" the 3-8 digits. As it stands my 2nd group will just support replacing with a fixed number of "*", so some adjustment would be needed. Hopefully this has helped you though to continue with a final solution. Terry

        N Offline
        N Offline
        NathanAsh
        wrote on last edited by
        #3

        hey Terry, Thanks for the suggestion. I am trying to achieve this patter replacement in java This one I thought of it but it is not working out for the input *1234 x1234 -1234 these kind of inputs should not be masked and output should be as it is *1234 / x1234 / -1234 whatever you have given works fine for *12345678 x12345678 -12345678

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups