reg Expression works until .,: or similar is in target string

ロック済み reg Expression works until .,: or similar is in target string

  • 2012年4月29日 8:53
     
     

    Hey out there,

    i was faced with the need to create an regular expression (this was without sucess) so an coworker helped me out and it worked fine until....

    The String works fine until there is a . or , or ; ... in the target, then the result is empty.

    The Expression (.Net) is: (?<=;#)(\w|\x20|-|\(|\))+(?=\|)

    The source string is: 544;#ProductName Version 1.0|d2bb1bee-a0fe-446b-9c23-d9329bbe72cd

    The result should be: ProductName Version 1.0  (the string between ;# and |)

    In case the target string is ProductName Version 10 everything is fine, but added ,. or similar there is no result....

    The Expression should work with all punctation marks

    Could anybody help mme with this.

    Not with the finnished string a realize how this works?!?! so i really need help!

    Thanks in advance!

    c_loki

    p.s. multi strings are separated by ; so this need to be trained to users (to not use them)

    • 編集済み c_loki 2012年4月29日 9:08 info added
    •  

すべての返信

  • 2012年4月29日 9:57
     
     回答済み
    On Sun, 29 Apr 2012 08:53:33 +0000, c_loki wrote:
     
    >The source string is: 544;#ProductName Version 1.0|d2bb1bee-a0fe-446b-9c23-d9329bbe72cd
    >
    >The result should be: ...  (the string between ;# and |)
     
    If you want the string between those two tokens, without lookarounds, then simply:
     
    ;#(?<TextString>[^|]+)
     
    will capture that into the named capturing group TextString.
     
    Or, if you want to use lookarounds, and no capturing groups:
     
    (?<=;#)[^|]+
     

    Ron
    • 回答としてマーク c_loki 2012年4月29日 10:32
    •  
  • 2012年4月29日 10:32
     
     

    Hi Ron,

    looks great! Thank you