#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Regular Expression error.


    I have a string "deOne 3 wjb2j1kk Two jkj[B212<221d>2w<xj21>]Onenn3n3[C14]dddd Two d"
    and patern : "One[^-(Two)]*Two"
    All I want is result:
    de<One 3 wjb2j1kk Two> jkj[B212<221d>2w<xj21>]Onenn3n3[C14]dddd Two d
    First match: One 3 wjb2j1kk Two at position 3
    Additional matches:
    Found: Onenn3n3[C14]dddd Two at position 46
    But I receive :
    deOne 3 wjb2j1kk Two jkj[B212<221d>2w<xj21>]<Onenn3n3[C14]dddd Two> d
    First match: Onenn3n3[C14]dddd Two at position 46
    Please give me a advice.

    Many thanks
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    Hi,

    A character class [...] consists of single characters (hence the name). So [^-(Two)] means: any character except one of the six characters "-", "(", "T", "w", "o", ")".

    What you're trying to do doesn't work that way and is much more complex. You're regex engine needs to support negative lookahead pattern.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    A character class [...] consists of single characters (hence the name). So [^-(Two)] means: any character except one of the six characters "-", "(", "T", "w", "o", ")".

    What you're trying to do doesn't work that way and is much more complex. You're regex engine needs to support negative lookahead pattern.
    Can you give me correct pattern ?

    thanks
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    I'd simply use a non-greedy quantifier:
    One.*?Two
    You might need to configure the "." pattern to also include new lines.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0
    thank you so much. .

IMN logo majestic logo threadwatch logo seochat tools logo