Search code examples
regexbarcode

Regex Expression - Cannot Drop The @ Sign


Hello guys having some regex issues. I am trying to parse a barcode that has the following format: #D0208#@01^ I need to be able to get the data after the @ and before the ^. My regex was working fine until I put a single piece of data in between the indicators such as #D0208#@1^ or #D0208#@A^ then everything fell apart and the @ sign was becoming troublesome. This is the regex code i'm currently working with: \w{0,}[^#D0208#\@\^\r] any ideas or regex gurus out there would be much appreciated.


Solution

  • I would take advantage of using character classes like this:

    [^@]+@([^^]+)\^
    

    That will match up to and including an @, then capture non ^ up to just before ^

    So if in English you are trying to capture what is between @ and ^ this will do the trick.

    You can play with it here: https://regex101.com/r/JPYMmJ/1