0

I have a string:

Input:

"Feature.. sklsd " AND klsdjkls 9290 "Feass . lskdk SDFSD __ ksdljsklfsd" NOT "Feuas" "Feature.lskd" OR PUT klasdkljf al9- .s.a, 9a0sd90209 .a,sdklf jalkdfj al;akd


I need to match any character except OR, NOT, AND, "Feature.any_count_of_characters"

the last one is important this start with: "Feature.

This is followed by any number of characters and then ends with: " character.

I'm trying to solve this using lookahead or lookbehind but I can get the expected output, only a portion of characters that I don't want.

My expected output is

"Feature.. sklsd " AND klsdjkls 9290 "Feass . lskdk SDFSD __ ksdljsklfsd" NOT "Feuas" "Feature.lskd" OR PUT klasdkljf al9- .s.a, 9a0sd90209 .a,sdklf jalkdfj al;akd

All that is in black.

To test it i'm using these links:

http://gskinner.com/RegExr/
http://regexpal.com/

Thanks.

EDIT

Check this link http://regexr.com?37v36

inside the link i get matched some expression. But i don't need the expression that matched. i need the inverse, how i can get it?

Thanks.

Pablo Pantaleon
  • 1,506
  • 1
  • 19
  • 38
  • Which language are you using? – Bohemian Jan 10 '14 at 22:39
  • Can you do another example? I'm really not understanding what you mean by `any charcter except OR, NOT, AND, "Feature.any_count_of_characters"` – Sam Jan 10 '14 at 22:40
  • 3
    ... or [this](http://stackoverflow.com/questions/6956010/c-sharp-regular-expression-excluding-a-string) or [this](http://stackoverflow.com/questions/116819/regular-expression-to-exclude-set-of-keywords) or [this](http://stackoverflow.com/questions/18241463/regex-exclude-matched-patterns) or [this](http://stackoverflow.com/questions/11781473/excluding-certain-patterns-in-a-regex) ... – O. R. Mapper Jan 10 '14 at 22:41
  • Thanks for your help O.R. Mapper. But i still having the same problem because i need the opposite of that i get. Let me edit my question. (I'm using Java) – Pablo Pantaleon Jan 10 '14 at 23:14

2 Answers2

1

Just use

\s*(?:AND|OR|NOT|"[^"]+")\s*

but do a replace operation. That will leave what you want.

Ron Rosenfeld
  • 53,870
  • 7
  • 28
  • 60
  • mjm.. nice.. i'm searching another way to do this.. but this works for now thanks. the thing is that i try to get a regexp because i need that in a group.. thats why i need inverse. i'll search in what other way i can get the inverse. – Pablo Pantaleon Jan 11 '14 at 17:31
  • Why do you need it in a group? Think about what you will do with the results and there may be an easy way of handling that issue with the result in a variable – Ron Rosenfeld Jan 11 '14 at 20:33
  • mm i think this in a group because i need to replace all text that are in the groups. Now i can replace text that match with \s*(?:AND|OR|NOT|"[^"]+")\s* with some custom string. But i need to match the inverse because i need to replace too with other custom string. – Pablo Pantaleon Jan 11 '14 at 22:57
0

Your basic problem is that look behinds can not have arbitrary lengths, but you need that. There are work arounds, but a simpler approach is to use a capturing group:

"Feature\.[^"]*" (?:OR|NOT|AND) ([^"])

And your target will be in group 1 of the match.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • Well, thats doesn't work because that code match the "Feature...." etc... but i need to match any character except "Feature...." etc. so the inverse. Please check the edit question. thanks for help. – Pablo Pantaleon Jan 11 '14 at 03:40