2

I am writing a Rational Functional Testing (RFT) script using Java language where I am trying to create an object in my object map with a regular expression not to match a certain pattern.

The URL which I want not to match will look something like:

http://AnyHostName/index.jsp?safe=active&q=arab&ie=UTF-8&oe=UTF-8&start=10
http://AnyHostName/index.jsp?safe=active&q=arab&ie=UTF-8&oe=UTF-8&start=40
http://AnyHostName/index.jsp?safe=active&q=arab&ie=UTF-8&oe=UTF-8&start=210

I tried using the below expression but since the end of the URL is also any number of two or more digits the expression failed to fulfill the need:

^.*(?<!\start=10)$   or   ^.*(?<!\start=40)$   or   ^.*(?<!\start=110)$

If i tried using \d+ to replace the number in the above patterns, the expression stopped working correctly.

Note: It is worth to mention that using any Java code will not be possible since the regular expression will be given to the tool (i.e. RFT) and it will be used internally for matching.

Any help please on this matter?

Sneftel
  • 40,271
  • 12
  • 71
  • 104
yazankhs
  • 173
  • 8
  • `\d` should work but `\s` is definitely wrong -- drop the backslash before the s. – tripleee Oct 05 '11 at 10:25
  • Apologies to everyone whom I got confused with the Java tag, I have modified the question accordingly. I have tried most of the solutions posted here and the solution provided by @Joaquim-Rendeiro solved my issue. – yazankhs Oct 05 '11 at 11:45

3 Answers3

1

why not just match

^http://AnyHostName/index.jsp?safe=active&q=arab&ie=UTF-8&oe=UTF-8&start=\d+$

(you have to do escape in java.)

and add a "!" in your java if statement?

like if (!m.match())...

Kent
  • 189,393
  • 32
  • 233
  • 301
  • As I have mentioned in the comment above, the tool prohibits the use of Java code although it is Java based. – yazankhs Oct 05 '11 at 11:49
1

Use this expression:

^(?:(?!start=\d+).)*$

It has the advantage that it excludes also the cases where start=10 appears in the middle of the URL (i.e. http://AnyHostName/index.jsp?safe=active&q=arab&start=210&ie=UTF-8&oe=UTF-8).

It can be slow, though, since it's checking the negative look-ahead for every character.

Joaquim Rendeiro
  • 1,388
  • 8
  • 13
  • You could make the negative lookahead anchored to & or $; that might help speed it up a bit. And if you don't have an anchor, the trailing plus is superfluous. `^(?:/(?!start=\d+(&|$)).)*$` – tripleee Oct 05 '11 at 11:52
  • 1
    But that's the thing, it doesn't work in that case. Try it here http://is.gd/XZuvRb – Joaquim Rendeiro Oct 05 '11 at 12:40
0

According to regular-expressions.info the look behind in java has to be of finite length. So \d+ would be infinite.

I am not sure, but you can try

^.*(?<!\start=\d{1,20})$

this quantifier {1,20} would allow any number of digits from 1 to 20 and should meet the finite criteria.

stema
  • 90,351
  • 20
  • 107
  • 135